Ibne Abbas narrates – I was with the Prophet (s.a.w.a.) while his son Ibrahim was seated on his left lap and Husain b. Ali (a.s.) was seated on his right lap. The Prophet (s.a.w.a.) was kissing them repeatedly, alternating between two children. Then Jibrail approached him with a revelation. After he (s.a.w.a.) concluded the matter with Jibrail he informed me – Jibrail came to me from his Lord and informed me – O Muhammad surely Allah conveys His salutations to you and commands you that both (these children) cannot survive, one of them will have to be relinquished for the other. The Prophet (s.a.w.a.) looked at Ibrahim and began weeping. Then he (s.a.w.a.) looked at Husain (a.s.) and began weeping. Then he (s.a.w.a.) said – Surely Ibrahim’s mother is a slave girl; when he passes away none will be aggrieved except me. While Husain’s mother is Fatimah and his father is Ali, my cousin and my flesh and blood. When Husain passes away, my daughter will be grief-struck and my cousin will be grief-struck and I will be grief-struck on account of their grief. I prefer to be grief-struck (over Ibrahim’s loss) rather than to see them grief-struck (over Husain’s loss). O Jibrail, you may capture Ibrahim’s soul, I have ransomed him over Husain. Three days later Ibrahim passed away. After that day whenever the Prophet (s.a.w.a.) saw Husain he used to kiss him and hold him closely to his chest and declare – I have been rescued by the one over whom I have ransomed my son Ibrahim.
Behaar al-Anwaar v 43, p 261 from Al-Manaaqeb