Sayyiduna Abdullah bin Ja'far (may Allah be pleased with him) narrates from Sayyiduna Ali bin Abi Talib (may Allah be pleased with him) that he said: "The Messenger of Allah (peace and blessings be upon him) taught me these words and commanded me that if any distress or hardships befell me, I should say: 'There is none worthy of worship except Allah, the Most Generous, the Forbearing. Glory be to Him, and blessed is Allah, Lord of the Mighty Throne. And all praise is for Allah, Lord of the worlds.'"
Related hadith on this topic