It is narrated from Abd Khayr al-Hadrami (may Allah have mercy on him), who narrates from Sayyiduna Zayd bin Arqam (may Allah be pleased with him); he said: Sayyiduna Ali (may Allah be pleased with him) was in Yemen when a woman was brought to him with whom three men had had relations in a single period of purity. He asked two of them: "Do you acknowledge this child for this (third) one?" They did not acknowledge it. Then he asked two: "Do you acknowledge the child for this one?" He kept asking two at a time in turn until he had asked all of them, and they did not acknowledge it. So he cast lots between them and assigned the child to the one whose lot came out, and obliged him to pay two-thirds of the blood money (diyah) to the other two. This matter was brought to 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المعجم الكبير للطبراني / باب الزاي / 4968