The Prophet ﷺ said, "The believers will gather on the Day of Resurrection and say, 'If only we sought someone to intercede for us with our Lord.'So they will come to Adam and say, 'You are the father of mankind. Allah created you with His own hand, made the angels prostrate to you, and taught you the names of all things. Intercede for us with your Lord so He may relieve us from this place we are in.'He will reply, 'I am not the one for that.' He will recall his sin and feel ashamed, and will say, 'Go to Nuh, for he was the first messenger Allah sent to the people of the earth.'So they will come to him, and he will say, 'I am not the one for that.' He will recall his asking his Lord about something he had no knowledge of, and will feel ashamed. He will say, 'Go to the Friend of the Most Merciful.'So they will come to him, and he will say, 'I am not the one for that. Go to Musa, a servant to whom Allah spoke and to whom He gave the Torah.'So they will come to him, and he will say, 'I am not the one for that.' He will recall his killing a soul without right and will feel ashamed before his Lord. He will say, 'Go to Isa, the servant of Allah, His messenger, His word, and a spirit from Him.'So they will come to him, and he will say, 'I am not the one for that. Go to Muhammad ﷺ, a servant whose past and future sins Allah has forgiven.'So they will come to me, and I will set out until I seek permission to approach my Lord, and permission will be granted to me. When I see my Lord, I will fall in prostration. He will leave me as long as Allah wills, then it will be said, 'Raise your head. Ask, and you shall be given. Speak, and you shall be heard. Intercede, and your intercession will be accepted.'So I will raise my head and praise Him with words of praise He teaches me, then I will intercede, and a limit will be set for me. I will admit them into Paradise. Then I will return to Him, and when I see my Lord, the same will happen. I will intercede, and a limit will be set for me, and I will admit them into Paradise. Then I will return a fourth time and say, 'No one remains in the Fire except those whom the Quran has confined and upon whom eternity has been decreed.'"Abu Abdullah said, "Those whom the Quran has confined" refers to Allah's saying, "abiding therein eternally" [Bayyinah 98:8].
عن النبي ﷺ قال: يجتمع المؤمنون يوم القيامة فيقولون لو استشفعنا إلى ربنا فأتوا آدم، فيقولون: أنت أبو الناس خلقك الله بيده، وأسجد لك ملائكته، وعلمك أسماء كل شيء، فاشفع لنا عند ربك حتى يريحنا من مكاننا هذا. فيقول: لست هناكم، ويذكر ذنبه فيستحي، اشتروا نوحا، فإنه أول رسول بعثه الله إلى أهل الأرض، فيأتونه فيقول: لست هناكم، ويذكر سؤاله ربه ما ليس له به علم فيستحي، فيقول: ائتوا خليل الرحمن، فيأتونه، فيقول: لست هناكم، اشتروا موسى عبدا كلمه الله وأعطاه التوراة. فيأتونه، فيقول: لست هناكم ويذكر قتل النفس بغير نفس فيستحي من ربه، فيقول: ائتوا عيسى عبد الله ورسوله وكلمة الله وروحه، فيقول: لست هناكم، ائتوا محمدا ﷺ عبدا غفر الله له ما تقدم من ذنبه وما تأخر فيأتوني، فأنطلق حتى أستأذن على ربي فيؤذن لي، فإذا رأيت ربي وقعت ساجدا، فيدعني ما شاء الله، ثم يقال: ارفع رأسك، وسل تعطه، وقل يسمع، واشفع تشفع. فأرفع رأسي فأحمده بتحميد يعلمنيه، ثم أشفع فيحد لي حدا فأدخلهم الجنة، ثم أعود إليه، فإذا رأيت ربي، مثله ثم أشفع فيحد لي حدا، فأدخلهم الجنة، ثم أعود الرابعة فأقول: ما بقي في النار إلا من حبسه القرآن ووجب عليه الخلود. قال أبو عبد الله: إلا من حبسه القرآن، يعني قول الله تعالى: {خالدين فيها}.
Bukhari reported it in the tafsir (4476), and Muslim in faith (193), both from the hadith of Hisham, from Qatada, from Anas, who mentioned it, and the wording is Bukhari's, while Muslim's wording is similar.