When Abu Talib was on the verge of death, the Prophet ﷺ came in to see him. Abu Jahl and Abdullah bin Abu Umaya were already there with him.The Prophet ﷺ said, "Uncle, say there is no god but Allah, so that I may plead for you with it before Allah."Abu Jahl and Abdullah bin Abu Khalaf said, "Abu Talib, would you turn away from the religion of Abdul-Muttalib?"The Prophet ﷺ then said, "I will keep asking forgiveness for you as long as I am not forbidden to do so."Then this was revealed, "It is not for the Prophet and those who believe to ask forgiveness for the idolaters, even if they are close relatives, after it has become clear to them that they are the companions of the Blaze" [Tawbah 9:113].
لما حضر أبا طالب الوفاة دخل عليه النبي ﷺ عنده أبو جهل وعبد الله بن أبي أمية فقال النبي ﷺ: أي عم قل لا إله إلا الله أحاج لك بها عند الله فقال أبو جهل وعبد الله بن أبي خلف: يا أبا طالب! أترغب عن ملة عبد المطلب؟ فقال النبي ﷺ لأستغفرن لك ما لم أنه عنك فنزلت: {ما كان للنبي والذين ءامنوا أن يستغفروا للمشركين ولو كانوا أولي قربى من بعد ما تبين لهم أنهم أصحب الجحيم} [سورة التوبة: ١١٣].
Bukhari narrated it in the tafsir (4675), and Muslim in the Book of Faith (24/40), both from Ishaq bin Ibrahim, who said, Abdul-Razzaq narrated to us, Maamar informed us, from Zuhri, from Saeed bin Musayab, from his father, and he related it. The wording given is that of Bukhari. In another version transmitted by Abdul-Razzaq as well, after his statement "then it was revealed," it adds, "and "Indeed, you do not guide whom you love" [Qasas 28:56] was revealed."