WE RELATE FROM Ibn as-Sunnī from Thawbān
, who related that when the Messenger of Allah
was frightened by something he would say: “He is Allah. Allah is my Lord; He has no partner.” [1].
Huwa-llāh, Allāhu Rabbī lā sharīka lah.
We relate in the Sunans of Abū Dāwūd and at-Tirmidhī from ‘Amr ibn Shu‘ayb, who reported from his father, who reported from his grandfather, that the Messenger of Allah
used to teach them these words for when they felt fear and terror: “I seek protection in the perfect words of Allah from His wrath and the evil of His servants, and from the promptings of the shayṭāns and from them approaching me.” [2].

A‘ūdhu bi-kalimāti-llāhi-t-tāmmāti min ghaḍabihi wa sharri ‘ibādih, wa min hamazāti-sh-shayāṭīn, 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 could not understand he would write it down and hang it [around their necks].
References
[1] Ibn as-Sunnī (337).
[2] Abū Dāwūd (3893) and at-Tirmidhī (3519).