Abu Dawud Book 6, Hadith Number 2262.
Narated By Zayd ibn Arqam : I was sitting with the Prophet (PBUH). A man came from the Yemen, and said: Three men from the people of the Yemen came to Ali, quarrelling about a child, asking him to give a decision. They had had sexual intercourse with a woman during a single state of purity.
He said to two of them: Give this child to this man (the third person) with pleasure. But they (refused and) cried loudly. Again he said to two of them: Give the child to the man (the third person) willingly. But they (refused and) cried loudly. He then said: You are quarrelsome partners. I shall cast lots among you; he who receives the lot, will acquire the child, and he shall pay two-thirds of the blood-money to both his companions. He then cast lots among them, and gave the child to the one who received the lot. The Apostle of Allah (PBUH) laughed so much that his canine or molar teeth appeared.