Abu Hurairah reported,

The Messenger of Allah ﷺ said, "An ifrit from the jinn came at me last night, trying to interrupt my prayer, but Allah gave me power over him and I seized him by the throat. I intended to tie him to one of the pillars of the mosque so that you could all look at him in the morning, then I remembered the words of my brother Sulayman, 'My Lord, forgive me and grant me a kingdom such as will not belong to anyone after me' [Sad 38:35], so Allah turned him away humiliated."

Azami 8457

Sahih

عن أبي هريرة قال

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

الأعظمي 8457صحيح
Contents
Reference
Commentary
Ayat
Collection
Jami al-Kamil
Book
Stories of the prophets
Chapter
Reports of Sulayman عليه السلام
Section
Greatness of the kingdom of Sulayman عليه السلام
Numbering
Jami al-Kamil 8457 (2nd edition)
Azami 8457