Abdullah bin al-Khalil narrates from Sayyiduna Zayd bin Arqam (may Allah be pleased with him); he said: The Messenger of Allah (peace and blessings be upon him) sent Sayyiduna Ali (may Allah be pleased with him) to Yemen, and three men were brought to him who had had relations with a woman in a single period of purity, and she gave birth to a child. He began asking them one by one: "Are you content that the child be his?" Then he said: "You are quarrelling partners." So he cast lots between them and assigned the child to the one whose lot came out, and imposed on him a penalty of two-thirds of the blood money (diyah) for the other two. This reached the Prophet (peace and blessings be upon him), and he (peace and blessings be upon him) laughed so much that his (peace and blessings be upon him) molar teeth became visible.
Hadith Referenceالمعجم الكبير للطبراني / باب الزاي / 4971