When death approached Abu Talib, the Prophet ﷺ came to him while Abu Jahl and Abdullah bin Abu Umaya were with him.The Prophet ﷺ said, "Uncle, say, 'There is no god but Allah,' a word by which I may plead for you before Allah ."Abu Jahl and Abdullah bin Abu Umaya said, "Abu Talib, will you turn away from the religion of Abdul-Muttalib?"They kept speaking to him until the last words he said to them were that he was upon the religion of Abdul-Muttalib.The Prophet ﷺ said, "I will surely seek forgiveness for you so long as I am not forbidden from doing so."Then the verse was revealed, "It is not fitting for the Prophet and those who believe to seek forgiveness for the polytheists" [Tawbah 9:113], and the verse was revealed, "Indeed, you do not guide whom you love" [Qasas 28:56].
أخبرنا محمد بن عبد الأعلى قال حدثنا محمد وهو ابن ثور عن معمر عن الزهري
لما حضرت أبا طالب الوفاة دخل عليه النبي ﷺ وعنده أبو جهل وعبد الله بن أبي أمية فقال أي عم قل لا إله إلا الله كلمة أحاج لك بها عند الله عز وجل فقال له أبو جهل وعبد الله بن أبي أمية يا أبا طالب أترغب عن ملة عبد المطلب فلم يزالا يكلمانه حتى كان آخر شيء كلمهم به على ملة عبد المطلب فقال له النبي ﷺ لأستغفرن لك ما لم أنه عنك فنزلت {ما كان للنبي والذين آمنوا أن يستغفروا للمشركين} ونزلت {إنك لا تهدي من أحببت}
Bukhari narrated it in "The Merits of the Ansar," the chapter on the story of Abu Talib, hadith no. 3884, and Muslim narrated it, and so on, hadith no. 24/240, from the hadith of Mamar bin Rashid, in "Faith," the chapter on the evidence for the validity of the Islam of one whom death approaches, and it is also found in Al-Kubra, hadith no. 2162.