WE RELATE FROM the Sunans of Abū Dāwūd, at-Tirmidhī and Ibn as-Sunnī, amongst others, from ‘Amr ibn Shu‘ayb who reported from his father who reported from his grandfather that the Messenger of Allah
used to teach the Companions these words for moments of fear and terror: “I seek protection in the perfect words of Allah from His wrath and from the evil of His slaves, and the enticements of demons, and from them approaching me.” [1].

A‘ūdhu bi-kalimāti-llāhi-t-tāmmāti min ghaḍabihi wa sharri ‘ibādih, wa min hamazāti-sh-shayāṭīni wa an yaḥḍurūn.
‘Abdullāh ibn ‘Amr used to teach these words to those of his children who could understand, and for those who did not understand he wrote it down and hung it [around their necks]. At-Tirmidhī classed this hadith as ḥasan.
According to Ibn as-Sunnī’s narration, a man complained to the Prophet
that he had been startled in his sleep, so the Messenger of Allah
said to him: “When you go to bed say: I seek protection in the perfect words of Allah from His wrath and His punishment, from the evil of His slaves and from the enticements of demons; so prevent them from appearing to me.” So he said that, and it left him.
References
[1] Abū Dāwūd (3893), at-Tirmidhī (3519), Ibn as-Sunnī (753), Aḥmad (2/181), and al-Ḥākim (1/548).