Imam Aḥmad, Musnad (1/391), and others reported upon the authority of Ibn Masʿūd that the Messenger of Allāh (ṣallallāhu ʿalayhi wa-sallam) said: “No slave is afflicted with anxiety and grief, and then says:
‘O Allāh, I am Your slave, son of Your male slave, son of Your female slave. My forehead is in Your hand. Your judgment upon me is assured and whatever you have decreed for me is just. I ask You by every name belonging to You which You have named Yourself with, revealed in Your Book, taught one of Your creation or which You have preserved in the knowledge of the Unseen with You that You make the Qurʾān the spring of my heart and the light of my chest, a banisher for my grief and a reliever for my anxiety.’
Except that Allāh will replace his distress and grief with joy.”
He was asked, ‘O Messenger of Allāh, should we not learn it?’ He said, “Of course, whoever hears it should learn it.”
Authenticated by Shaykh al-Albānī in al-Silsilah al Aḥadīth al-Ṣaḥihah (1/198)’ with a slightly different wording. And this wording was declared ḥasan (sound) by Shaykh ʿAlī in his checking of al-Fawāʾid al-al-Fawāʾid pg. 49.