It is narrated from Sayyiduna Ibn Abbas (may Allah be pleased with them both): "the Messenger of Allah (peace and blessings be upon him) performed Umrah, and it had been agreed between him (peace and blessings be upon him) and the people of Makkah that he would not take any of its people out with him. So when the Messenger of Allah (peace and blessings be upon him) had completed his Umrah and was leaving Makkah, he (peace and blessings be upon him) passed by the daughter of Sayyiduna Hamzah bin Abd al-Muttalib (may Allah be pleased with him). She called out: 'O Messenger of Allah, to whom are you leaving me?' But he (peace and blessings be upon him) did not turn towards her, in keeping with the covenant made with the people of Makkah. Then Sayyiduna Zayd bin Harithah (may Allah be pleased with him) passed by her, and she said the same to him, but he too paid no attention. Then Sayyiduna Ja'far (may Allah be pleased with him) passed by, and she appealed to him as well, but he too did not turn towards her. Then, when Sayyiduna Ali bin Abi Talib (may Allah be pleased with him) passed by there, she said: 'O Abu al-Hasan, to whom are you leaving me?' So Sayyiduna Ali (may Allah be pleased with him) took her and seated her on the mount behind Sayyidah Fatimah (may Allah be pleased with her). Then, when they stopped at the first halting place, Sayyiduna Zayd (may Allah be pleased with him) said to Sayyiduna Ali (may Allah be pleased with him): 'I have more right to her, because I am the freed slave of the Prophet of Allah (peace and blessings be upon him).' Sayyiduna Ali (may Allah be pleased with him) said: 'I have more right to her.' And Sayyiduna Ja'far (may Allah be pleased with him) said: 'I have more right to her, because her maternal aunt, Sayyidah Asma' bint Umays (may Allah be pleased with her), is married to me.' When their voices rose in the dispute, the Messenger of Allah (peace and blessings be upon him) sent for them. When they came to him, he (peace and blessings be upon him) said: 'O Ja'far, you resemble me in appearance and in character; O Ali, I am from you and you are from me; and O Zayd, you are my mawla and the mawla of you all. So hand the girl over to her maternal aunt, for the maternal aunt has the greater right (to custody).'"
Abu Bakr bin Abi Shaybah recorded it, and its wording has passed in the Book of Judgments; Imam Abu Ya'la also recorded it with a da'if (weak) chain, and this wording is his. Its basis is established in the Sahih (al-Bukhari) from the hadith of Sayyiduna al-Bara' bin Azib (may Allah be pleased with him), and Imam al-Tirmidhi and Ibn Majah recorded it from the hadith of Sayyiduna Ali bin Abi Talib (may Allah be pleased with him).