When Abu Talib was on the verge of death, 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 statement with which I will plead on your behalf before Allah."Abu Jahl and Abdullah bin Ubayy bin Khalaf said, "Abu Talib, will you turn away from the religion of Abdul Muttalib?"The Prophet ﷺ said, "I will surely seek forgiveness for you as long as I am not forbidden to do so."Then the following verse was revealed, "It is not for the Prophet and those who have believed to ask forgiveness for the polytheists, even if they were relatives, after it has become clear to them that they are companions of Hellfire." [Tawba 9:113]
لما حضر أبا طالب الوفاة دخل عليه النبي ﷺ وعنده أبو جهل، وعبد الله بن أبي أمية، فقال النبي ﷺ: أي عم، قل: لا إله إلا الله أحاج لك بها عند الله، فقال أبو جهل، وعبد الله بن أبي بن خلف: يا أبا طالب، أترغب عن ملة عبد المطلب؟ فقال النبي ﷺ: لأستغفرن لك ما لم أنه عنك، فنزلت: {ما كان للنبي والذين آمنوا أن يستغفروا للمشركين ولو كانوا أولي قربى من بعد ما تبين لهم أنهم أصحاب الجحيم} [سورة التوبة: ١١٣].
Narrated by Bukhari in tafsir (4675) and Muslim in Iman (24/40), both from Ishaq bin Ibrahim, who said, Abdul-Razzaq narrated to us, Mamar informed us, from Zuhri, from Saeed bin Musayab, from his father, and he related it. The wording given here is Bukhari's.In another version, also from Abdul-Razzaq, after his statement it was revealed, "It was not fitting for the Prophet...", it adds that it was also revealed, "Indeed, you do not guide whom you love" [Qasas 28:56].