Sayyiduna Abdullah bin Ja'far (may Allah be pleased with him) narrates from Sayyiduna Ali (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 severe distress befell me, I should say them: 'There is none worthy of worship except Allah, the Forbearing, the Most Generous. Glory be to Him, and most blessed is Allah, Lord of the Mighty Throne. And all praise is for Allah, Lord of the worlds.'"
Imam Ahmad (may Allah have mercy on him) narrated it from Rawh bin Ubadah (may Allah have mercy on him).