When Abu Talib was on his deathbed, the Messenger of Allah ﷺ came to him and found Abu Jahl and Abdullah bin Abu Umaya bin Mughira with him.The Messenger of Allah ﷺ said, "Uncle, say there is no god but Allah, a single word by which I may plead for you before Allah."Abu Jahl and Abdullah bin Abu Umaya said, "Are you turning away from the religion of Abdul-Muttalib?"The Messenger of Allah ﷺ kept presenting it to him, and the two kept repeating their words to him, until the last thing Abu Talib said to them was that he was on the religion of Abdul-Muttalib, and he refused to say there is no god but Allah.The Messenger of Allah ﷺ said, "By Allah, I will keep seeking forgiveness for you so long as I am not forbidden to do so."Then Allah 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]And Allah revealed concerning Abu Talib, saying to the Messenger of Allah ﷺ, "Indeed, you do not guide whom you love, but Allah guides whom He wills, and He is most knowing of the rightly guided." [Qasas 28:56]
لما حضرت أبا طالب الوفاة جاءه رسول الله ﷺ فوجد عنده أبا جهل، وعبد الله بن أبي أمية بن المغيرة، فقال: أى عم قل لا إله إلا الله، كلمة أحاج لك بها عند الله. فقال أبو جهل و عبد الله بن أبي أمية: أترغب عن ملة عبد المطلب؟ فلم يزل رسول الله ﷺ يعرضها عليه، ويعيدانه بتلك المقالة حتى قال أبو طالب آخر ما كلمهم: على ملة عبد المطلب، وأبى أن يقول: لا إله إلا الله. قال: قال رسول الله ﷺ: والله لأستغفرن لك ما لم أنه عنك. فأنزل الله: {ما كان للنبي والذين آمنوا أن يستغفروا للمشركين ولو كانوا أولي قربى من بعد ما تبين لهم أنهم أصحاب الجحيم}[سورة التوبة: ١١٣] وأنزل الله فى أبي طالب فقال لرسول الله ﷺ: {إنك لا تهدي من أحببت ولكن الله يهدى من يشاء وهو أعلم بالمهتدين}
Bukhari narrated it in the tafsir (4772), and Muslim in the faith (24), both through Ibn Shihab Zuhri, who said, "Saeed bin Musayab informed me," and he related it. The wording given is Bukhari's.