The Prophet ﷺ said, "On the Day of Resurrection, the believers will gather and say, 'If only we could seek someone to intercede for us with our Lord.' So they will go to Adam and say, 'You are the father of mankind. Allah created you with His own hand, made His 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.'Adam will reply, 'I am not the one for that.' He will recall his sin and feel ashamed. He will say, 'Go to Nuh, for he was the first messenger Allah sent to the people of the earth.'So they will go to Nuh, and he will say, 'I am not the one for that.' He will recall how he asked his Lord about something he had no knowledge of, and he will feel ashamed. He will say, 'Go to the Friend of the Most Merciful.'So they will go to him, and he will say, 'I am not the one for that. Go to Musa, a servant whom Allah spoke to and to whom He gave the Torah.'So they will go to him, and he will say, 'I am not the one for that.' He will recall his killing of a soul without right and feel ashamed before his Lord. He will say, 'Go to Isa, the servant of Allah, His messenger, His word, and a spirit from Him.'Isa 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. When I see my Lord, I will fall down in prostration. He will leave me as long as He wills, then it will be said, 'Raise your head. Ask, and you will be given. Speak, you will be heard. Intercede, your intercession will be accepted.'So I will raise my head and praise Him with a praise He will teach me. Then I will intercede, and He will set a limit for me, and I will admit them into Paradise.Then I will return to Him, and when I see my Lord, the same will happen. Then I will intercede, and He will set a limit 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 detained and upon whom eternity has been decreed.'"
عن النبي ﷺ قال: يجتمع المؤمنون يوم القيامة، فيقولون: لو استشفعنا إلى ربنا، فيأتون آدم، فيقولون: أنت أبو الناس، خلقك الله بيده، وأسجد لك ملائكته، وعلمك أسماء كل شيء، فاشفع لنا عند ربك حتى يريحنا من مكاننا هذا. فيقول: لست هناكم، ويذكر ذنبه، فيستحيي، ائتوا، نوحا فإنه أول رسول بعثه الله إلى أهل الأرض فيأتونه، فيقول: لست هناكم، ويذكر سؤاله ربه ما ليس له به علم، فيستحيي، فيقول: ائتوا خليل الرحمن فيأتونه، فيقول: لست هناكم ائتوا موسى عبدا كلمه الله، وأعطاه التوراة. فيأتونه، فيقول: لست هناكم. ويذكر قتل النفس بغير نفس، فيستحيي من ربه، فيقول: ائتوا عيسى عبد الله ورسوله وكلمة الله وروحه فيقول: لست هناكم ائتوا محمد ﷺ عبدا غفر الله له ما تقدم من ذنبه وما تأخر. فيأتوني، فأنطلق حتى أستأذن على ربي، فيؤذن لي، فإذا رأيت ربي، وقعت ساجدا، فيدعني ما شاء الله، ثم يقال: ارفع رأسك، وسل تعطه، وقل: يسمع، واشفع تشفع، فأرفع رأسي، فأحمده بتحميد يعلمنيه، ثم أشفع، فيحد لي حدا، فأدخلهم الجنة، ثم أعود إليه، فإذا رأيت ربي-مثله- ثم أشفع، فيحد لي حدا، فأدخلهم الجنة، ثم أعود الرابعة، فأقول ما بقي النار إلا من حبسه القرآن، ووجب عليه الخلود.
Bukhari narrated it in the tafsir chapter (4476), and Muslim in the book of faith (193), both from the hadith of Hisham, from Qatada, from Anas, as mentioned. The wording is Bukhari's.