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."
قال رسول الله ﷺ: إن عفريتا من الجن جعل يفتك علي البارحة ليقطع علي الصلاة وإن الله أمكنني منه فذعته فلقد هممت أن أربطه إلى جنب سارية من سواري المسجد حتى تصبحوا تنظرون إليه أجمعون- أو كلكم- ثم ذكرت قول أخي سليمان {رب اغفر لي وهب لي ملكا لا ينبغي لأحد من بعدي} فرده الله خاسئا.
Bukhari related it in the Book of Prayer (461), and Muslim in the Book of Prayer (541), both from the hadith of Shubah, who said, Muhammad bin Ziyad narrated to us, saying, I heard Abu Hurairah say, and then he mentioned it. The wording given here is that of Muslim, and the wording of Bukhari is similar. His statement, "fa dhaattuhu," means "I strangled him."