Abu Hurairah reported,

The Messenger of Allah ﷺ said, "An ifrit from the jinn came at me last night trying to break my prayer, but Allah gave me power over him, so I seized him by the throat. I was about to tie him to one of the pillars of the mosque so that you could all see him in the morning, then I remembered the words of my brother Sulayman, 'My Lord, forgive me and grant me a kingdom that shall not belong to anyone after me' [Sad 38:35]. So Allah sent him back humiliated."Ibn Mansur said, Shuba narrated it from Muhammad bin Ziyad.

Muslim 1209

Sahih

حدثنا إسحق بن إبراهيم وإسحق بن منصور قالا أخبرنا النضر بن شميل أخبرنا شعبة حدثنا محمد وهو ابن زياد قال سمعت

أبا هريرة يقول

ا قال رسول الله ﷺ إن عفريتا من الجن جعل يفتك علي البارحة ليقطع علي الصلاة وإن الله أمكنني منه فذعته فلقد هممت أن أربطه إلى جنب سارية من سواري المسجد حتى تصبحوا تنظرون إليه أجمعون أو كلكم ثم ذكرت قول أخي سليمان {رب اغفر لي وهب لي ملكا لا ينبغي لأحد من بعدي} فرده الله خاسئا و قال ابن منصور شعبة عن محمد بن زياد

مسلم 1209صحيح
Contents
Reference
Commentary
Ayat
Collection
Sahih Muslim
Book
Mosques and places of prayer
Chapter
Permissibility of cursing Satan during prayer, seeking refuge from him, and permissibility of minor actions in prayer
Numbering
Darussalam 1209
Muslim 1209