Ibn al-Sunnī also related in The Practice of the Day and Night from Muhammad ibn al-Munkadir, who said: A man came to the Prophet—peace and blessings be upon him—and complained to him of terrifying visions he saw in his dreams. He said: “When you retire to your bed, say: ‘I seek refuge in the perfect words of Allah from His wrath and punishment, from the evil of His servants, and from the promptings of the devils and their presence.’”1.
This is a magnificent supplication that the Prophet—peace and blessings be upon him—instructed anyone afflicted in his sleep by fright and fear on account of terrifying things he may see in his dreams to recite, so that his fright may leave him, his soul may find peace, he may rest calmly and quietly in his sleep, and his fear and terror may depart. It is a magnificent and blessed supplication in which the servant declares his recourse to Allah, his seeking protection in Him, and his flight to Him from His wrath and punishment—glorified is He—from the evil of His servants, from the promptings of the devils, and from their drawing near to him, whether while he is asleep or in any other state.
The Prophet—peace and blessings be upon him—stated that whoever says it will not be harmed by the devils; rather, he will remain safe and sound from them.
His words, “I seek refuge in the perfect words of Allah,” mean: I seek shelter. Seeking refuge means turning to Allah for shelter and protection. One who seeks refuge in Allah flees from everything that may harm him to his Lord—glorified is He—in whose hand are the reins of all affairs and the governance of all creation. The perfect words of Allah are those untouched by any deficiency or flaw, unlike human speech.
His words, “from His wrath and punishment”: Wrath is an affirmed attribute of action belonging to Allah—exalted is He. He described Himself by it in His Book, and His Messenger—peace and blessings be upon him—described Him by it in his Sunnah. He, majestic and exalted, becomes angry, is pleased, loves, and hates, and He has many attributes of action mentioned in the Book