When Abu Taalib was close to breathing his last, Rasulullah (sallallahu ‘alaihi wasallam) came to him. At that time, Abu Jahal and ‘Abdullah bin Abi Umayyah were also present at his bedside. Rasulullah (sallallahu ‘alaihi wasallam) encouraged Abu Taalib saying, “O my uncle! Recite the kalimah Laa ilaaha illallaah just once so that I will have a basis to intercede for you before Allah.”
Hearing this, Abu Jahal and ‘Abdullah bin Abi Umayyah immediately interrupted and said, “O Abu Taalib! Are you renouncing the religion of ‘Abdul Muttalib?” Hence, Abu Taalib refused to recite the kalimah, and the last words on his tongue, before passing away, were, “On the religion of ‘Abdul Muttalib (in other words, I am passing away on the religion of ‘Abdul Muttalib).” Saying these words, Abu Taalib passed away.
After Abu Taalib passed away, Rasulullah (sallallahu ‘alaihi wasallam) said, “I will continue to make du‘aa for his forgiveness, so long as I am not prohibited from doing so by Allah Ta‘ala.” Upon this, the following verse of the Qur’aan Majeed was revealed:
مَا کَانَ لِلنَّبِیِّ وَ الَّذِیۡنَ اٰمَنُوۡۤا اَنۡ یَّسۡتَغۡفِرُوۡا لِلۡمُشۡرِکِیۡنَ وَ لَوۡ کَانُوۡۤا اُولِیۡ قُرۡبٰی مِنۡۢ بَعۡدِ مَا تَبَیَّنَ لَہُمۡ اَنَّہُمۡ اَصۡحٰبُ الۡجَحِیۡمِ ﴿۱۱۳﴾
It is not (permissible) for the Prophet and the believers to seek forgiveness for the disbelievers, even if they are relatives, after it became clear to them that they are the people of Jahannum. (Surah Towbah v. 113)
The following verse was also revealed:
اِنَّکَ لَا تَہۡدِیۡ مَنۡ اَحۡبَبۡتَ وَ لٰکِنَّ اللّٰہَ یَہۡدِیۡ مَنۡ یَّشَآءُ
You cannot give guidance to whomsoever you wish, but Allah gives guidance to whomsoever He wills. (Surah Qasas v. 56)
(Extracted from Seeratul Mustafa 1/271-272)