The Prophet ﷺ said, "An ifrit from among the jinn came at me suddenly last night," or words to that effect, "trying to interrupt my prayer. But Allah gave me power over him, so I seized him and intended to tie him to one of the pillars of the mosque so that all of you could look at him in the morning. Then I remembered the supplication 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 I sent him away humiliated."Ifrit means a rebellious one from among humans or jinn, like zibniyah, whose plural is zabaniyah.
عن النبي ﷺ قال: إن عفريتا من الجن تفلت علي البارحة- أو كلمة نحوها- ليقطع علي صلاتي. فأمكنني الله منه فأخذته فأردت أن أربطه على سارية من سواري المسجد حتى تنظروا إليه كلكم. فذكرت دعوة أخي سليمان: {رب اغفر لي وهب لي ملكا لا ينبغي لأحد من بعدى} [سورة ص: ٣٥] فرددته خاسئا. عفريت: متمرد من إنس أو جان مثل زبنية جماعتها الزبانية.
Bukhari narrated it in the Hadiths of the Prophets (3423), and Muslim in the Masjids (541), both from Muhammad bin Bashshar, who said, Muhammad bin Jafar narrated to us, who said, Shuba narrated to us, from Muhammad bin Ziyad, who said, I heard Abu Hurairah, and he mentioned the hadith, with the wording being Bukhari's.Muslim added, in Nadr bin Shumayl's narration from Shuba, after the phrase "Then Allah gave me power over him," the word fadhaatuhu, with the dotted dhal and a light, undoubled ayn, meaning I strangled him. Then Muslim said, As for Ibn Abu Shayba (from Shababa, from Shuba), he said in his narration, fadaatuhu, with the undotted dal, meaning I pushed him with great force.Nawawi said, "Khattabi rejected the undotted version and said it is not correct, but others confirmed it as correct and validated it, even though the dotted version is clearer and better known. This hadith is evidence for the permissibility of performing a small action during prayer."As for his statement, "Then I remembered the words of my brother Sulayman..." this means that the Prophet ﷺ was able to tie him to a pillar of the masjid, but when he remembered the words of Sulayman , he refrained from doing so out of humility and good manners. His ﷺ being given power over the jinn is not a contradiction of Allah's saying, "Grant me a kingdom such as will not befit anyone after me" [Sad 38:35], since a small matter of this sort does not invalidate the exclusiveness of the complete kingdom granted to Sulayman.As for his statement, "until all of you could look at him," this is evidence that seeing jinn is not impossible. As for Allah's saying, "Indeed, he and his tribe see you from where you do not see them" [Araf 7:27], this describes the general and predominant case among human beings, whom He tested with this so that they would turn to Him
in alarm and seek refuge in Him from their evil.See Sharh al-Sunnah (3/270).