In al-Saheehayn it was reported from Ibn ‘Abbaas that the Messenger of Allah used to say, when he felt distressed:

“La ilaaha ill-Allaah al-‘Azeem ul-Haleem, Laa ilaaha ill-Allaah Rabb il-‘arsh il-‘azeem, Laa ilaaha ill-Allaah Rabb is-samawaati wa Rabb il-ard wa Rabb il-‘arsh il-kareem.”

(There is no god except Allah, the All-Mighty, the Forbearing; there is no god except Allah, the Lord of the Mighty Throne; there is no god except Allah, Lord of the heavens, Lord of the earth and Lord of the noble Throne).”

And it was reported from Anas RA that the Prophet S.A.W. used to say, when something upset him:

“Yaa Hayyu yaa Qayyoom, bi Rahmatika astagheeth.”

(O Ever-Living One, O Everlasting One, by Your mercy I seek help.)

And it was reported that Asmaa’ bint ‘Umays RA said:

The Messenger of Allah said to me: “Shall I not teach you some words to say when you feel distressed?”

“Allaah, Allaah, Rabbee laa ushriku bihi shay’an.”

(Allah, Allah, my Lord, I do not associate anything with Him.)

It was reported from ‘Abd-Allaah ibn Mas’ood that the Prophet S.A.W. said:

“No person suffers any anxiety or grief, and says:

“‘Allaahumma innee ‘abduka wa ibn ‘abdika wa ibn amatika, naasiyati bi yadika, maadin fiyya hukmuka, ‘adlun fiyya qadaa’uka, as’aluka bi kulli ismin huwa laka sammayta bihi nafsaka aw anzaltahu fi kitaabika aw ‘allamtahu ahadan min khalqika aw ista’tharta bihi fi ‘ilm il-ghaybi ‘andak an taj’ala al-Qur’aana rabee’ qalbi wa noor sadri wa jalaa’a huzni wa dhahaaba hammi.”

“O Allah, I am Your slave, son of Your slave, son of Your female slave, my forelock is in Your hand, Your command over me is forever executed and Your decree over me is just. I ask You by every Name belonging to You which You named Yourself with, or revealed in Your Book, or You taught to any of Your creation, or You have preserved in the knowledge of the unseen with You, that You make the Qur’aan the life of my heart and the light of my breast, and a departure for my sorrow and a release for my anxiety.”

“…but Allah will take away his sorrow and grief, and give him in their stead joy.”

[Al-Kalim al-Tayyib by Shaykh al-Islam Ibn Taymiyah, edited by Shaykh al-Albaani, p. 72]