Mishkat al-Masabih
Mishkat al-Masabih 374
How to act when relieving oneself - Section 3
Arabic hadith text
وَعَنْ أَنَسٍ قَالَ: كَانَ النَّبِيُّ صَلَّى اللَّهُ عَلَيْهِ وَسَلَّمَ: إِذَا خَرَجَ مِنَ الْخَلَاءِ قَالَ: «الْحَمْدُ لِلَّهِ الَّذِي أَذْهَبَ عَنِّي الْأَذَى وَعَافَانِي» . رَوَاهُ أبن مَاجَه
Translation
Anas reported that when the Prophet came out of the privy he said, “Praise be to God who has removed harm from me and kept me in health.” Ibn Majah transmitted it.