When the idol worshippers of Makka found out that Prophet Muhammad (S) was preaching against their idol worship, they were very angry. They made a plot to kill him. Allah informed the Prophet (S) about their plans and told him to migrate with the Muslims to Madina. This migration is called the Hijrat.
The night that the Prophet (S) left for Madina, 40 men from different tribes had gathered around his house to kill him. The Prophet (S) asked Imam Ali (A) if he would sleep in his bed so that the idol worshippers outside would think that the Prophet (S) was still there. The Imam (A) was very happy to do this, because he knew that the life of the Prophet (S) would be saved by his action. In fact, the Imam (A) used to say later that the best sleep he had ever had was on that night.
Allah said to the angels Jibra'eel and Mika'eel that one of them had a longer time to live than the other - he asked the angels whether either one of them would agree for the other to have the longer life. They both replied that they each would like to live longer so that they could worship Allah more. Allah then informed them, "On the earth tonight, one brother is willing to give up his life for the safety of his brother. Go down, and protect him."
Both angels came down to the house of the Prophet (S) and looked after the Imam (A) all night long. At dawn time, the killers rushed into the Prophet's (S) house and pulled off the blanket. They were amazed to see Imam Ali (A) there, and so they left angrily.1 Allah liked this action of the Imam (A) so much that he revealed a verse in the Qur'an:
And of the people is he who sells himself, seeking means to the approval of Allah. And Allah is kind to [His] servants.2
Ahadith from Imam Ali
Do not look at who is speaking, but look at what he is saying. 3
1. al-Qundoo:zi, Yanabi al-Mawadda, pg 274
وَمِنَ النَّاسِ مَن يَشْرِي نَفْسَهُ ابْتِغَاءَ مَرْضَاتِ اللَّـهِ ۗ وَاللَّـهُ رَءُوفٌ بِالْعِبَادِ
3. Ghurar al-Hikam, chapter 85, hadith 40