Language:
كتاب الجنائز
23  
Funerals (Al-Janaa'iz)
(80)
Chapter: If Al-Mushrik says, "La ilaha illallah" at the time of his death
(80)
باب إِذَا قَالَ الْمُشْرِكُ عِنْدَ الْمَوْتِ لاَ إِلَهَ إِلاَّ اللَّهُ
Sahih al-Bukhari 1360

Narrated Sa`id bin Al-Musaiyab from his father:

When the time of the death of Abu Talib approached, Allah's Messenger (ﷺ) went to him and found Abu Jahl bin Hisham and `Abdullah bin Abi Umaiya bin Al-Mughira by his side. Allah's Messenger (ﷺ) said to Abu Talib, "O uncle! Say: None has the right to be worshipped but Allah, a sentence with which I shall be a witness (i.e. argue) for you before Allah. Abu Jahl and `Abdullah bin Abi Umaiya said, "O Abu Talib! Are you going to denounce the religion of `Abdul Muttalib?" Allah's Messenger (ﷺ) kept on inviting Abu Talib to say it (i.e. 'None has the right to be worshipped but Allah') while they (Abu Jahl and `Abdullah) kept on repeating their statement till Abu Talib said as his last statement that he was on the religion of `Abdul Muttalib and refused to say, 'None has the right to be worshipped but Allah.' (Then Allah's Messenger (ﷺ) said, "I will keep on asking Allah's forgiveness for you unless I am forbidden (by Allah) to do so." So Allah revealed (the verse) concerning him (i.e. It is not fitting for the Prophet (ﷺ) and those who believe that they should invoke (Allah) for forgiveness for pagans even though they be of kin, after it has become clear to them that they are companions of the fire (9.113).

حَدَّثَنَا إِسْحَاقُ، أَخْبَرَنَا يَعْقُوبُ بْنُ إِبْرَاهِيمَ، قَالَ حَدَّثَنِي أَبِي، عَنْ صَالِحٍ، عَنِ ابْنِ شِهَابٍ، قَالَ أَخْبَرَنِي سَعِيدُ بْنُ الْمُسَيَّبِ، عَنْ أَبِيهِ، أَنَّهُ أَخْبَرَهُ أَنَّهُ، لَمَّا حَضَرَتْ أَبَا طَالِبٍ الْوَفَاةُ جَاءَهُ رَسُولُ اللَّهِ صلى الله عليه وسلم فَوَجَدَ عِنْدَهُ أَبَا جَهْلِ بْنَ هِشَامٍ، وَعَبْدَ اللَّهِ بْنَ أَبِي أُمَيَّةَ بْنِ الْمُغِيرَةِ، قَالَ رَسُولُ اللَّهِ صلى الله عليه وسلم لأَبِي طَالِبٍ ‏"‏ يَا عَمِّ، قُلْ لاَ إِلَهَ إِلاَّ اللَّهُ، كَلِمَةً أَشْهَدُ لَكَ بِهَا عِنْدَ اللَّهِ ‏"‏‏.‏ فَقَالَ أَبُو جَهْلٍ وَعَبْدُ اللَّهِ بْنُ أَبِي أُمَيَّةَ يَا أَبَا طَالِبٍ، أَتَرْغَبُ عَنْ مِلَّةِ عَبْدِ الْمُطَّلِبِ فَلَمْ يَزَلْ رَسُولُ اللَّهِ صلى الله عليه وسلم يَعْرِضُهَا عَلَيْهِ، وَيَعُودَانِ بِتِلْكَ الْمَقَالَةِ، حَتَّى قَالَ أَبُو طَالِبٍ آخِرَ مَا كَلَّمَهُمْ هُوَ عَلَى مِلَّةِ عَبْدِ الْمُطَّلِبِ، وَأَبَى أَنْ يَقُولَ لاَ إِلَهَ إِلاَّ اللَّهُ‏.‏ فَقَالَ رَسُولُ اللَّهِ صلى الله عليه وسلم ‏"‏ أَمَا وَاللَّهِ لأَسْتَغْفِرَنَّ لَكَ، مَا لَمْ أُنْهَ عَنْكَ ‏"‏‏.‏ فَأَنْزَلَ اللَّهُ تَعَالَى فِيهِ ‏{‏مَا كَانَ لِلنَّبِيِّ‏}‏ الآيَةَ‏.‏
Reference : Sahih al-Bukhari 1360
In-book reference : Book 23, Hadith 113
USC-MSA web (English) reference : Vol. 2, Book 23, Hadith 442
  (deprecated numbering scheme)