It is narrated on the authority of Abu Huraira that the Messenger of Allah said to his uncle at the time of his death:
Make a testimony of it that there is no god but Allah and I will bear testimony (of your being a Muslim) on the Day of judgment. But he (Abu Talib) refused to do so. Then Allah revealed this verse: ” Verily thou canst not guide to the right path whom thou lovest. And it is Allah Who guideth whom He will and He knoweth best who are the guided” (Al-Qasas 56).
حَدَّثَنَا مُحَمَّدُ بْنُ عَبَّادٍ، وَابْنُ أَبِي عُمَرَ، قَالاَ حَدَّثَنَا مَرْوَانُ، عَنْ يَزِيدَ، – وَهُوَ ابْنُ كَيْسَانَ – عَنْ أَبِي حَازِمٍ، عَنْ أَبِي هُرَيْرَةَ، قَالَ قَالَ رَسُولُ اللَّهِ صلى الله عليه وسلم لِعَمِّهِ عِنْدَ الْمَوْتِ ” قُلْ لاَ إِلَهَ إِلاَّ اللَّهُ أَشْهَدُ لَكَ بِهَا يَوْمَ الْقِيَامَةِ ” . فَأَبَى فَأَنْزَلَ اللَّهُ { إِنَّكَ لاَ تَهْدِي مَنْ أَحْبَبْتَ} الآيَةَ .
Reference : Sahih Muslim 25a
In-book reference : Book 1, Hadith 41
USC-MSA web (English) reference : Book 1, Hadith 37
