The Messenger of Allah ﷺ said, "When one of you is frightened during sleep, let him say, 'I seek refuge in the perfect words of Allah from His anger, His punishment, the evil of His servants, the whisperings of the devils, and lest they come near me.' Then it will not harm him."Abdullah bin Umar used to teach these words to those of his children who had reached the age of understanding, and for those who had not yet reached it, he would write the words on a piece of parchment and hang it around the child's neck.
حدثنا علي بن حجر حدثنا إسمعيل بن عياش عن محمد بن إسحق
أن رسول الله ﷺ قال إذا فزع أحدكم في النوم فليقل أعوذ بكلمات الله التامات من غضبه وعقابه وشر عباده ومن همزات الشياطين وأن يحضرون فإنها لن تضره وكان عبد الله بن عمر يلقنها من بلغ من ولده ومن لم يبلغ منهم كتبها في صك ثم علقها في عنقه
[Its chain of transmission is daif] Reference: Abu Dawud also narrated it in the Chapter on Medicine, Chapter How to Perform Incantations, no. 3893, from the hadith of Ibn Ishaq through this same chain, using the ambiguous form "an" (indicating a possible break in transmission). Nevertheless, Hakim graded it sahih in 1/548, and Munziri graded it hasan.