حَدَّثَنَا عَلِيُّ بْنُ مُحَمَّدٍ، حَدَّثَنَا وَكِيعٌ، عَنْ خَارِجَةَ بْنِ مُصْعَبٍ، عَنْ أَبِي يَحْيَى، عَمْرِو بْنِ دِينَارٍ - وَلَيْسَ بِصَاحِبِ ابْنِ عُيَيْنَةَ - مَوْلَى آلِ الزُّبَيْرِ عَنْ سَالِمٍ، عَنِ ابْنِ عُمَرَ، قَالَ قَالَ رَسُولُ اللَّهِ ـ صلى الله عليه وسلم ـ ‏"‏ مَنْ فَجِئَهُ صَاحِبُ بَلاَءٍ فَقَالَ الْحَمْدُ لِلَّهِ الَّذِي عَافَانِي مِمَّا ابْتَلاَكَ بِهِ وَفَضَّلَنِي عَلَى كَثِيرٍ مِمَّنْ خَلَقَ تَفْضِيلاً - عُوفِيَ مِنْ ذَلِكَ الْبَلاَءِ كَائِنًا مَا كَانَ ‏"‏ ‏.‏

It was narrated from Ibn ‘Umar that the Messenger of Allah (PBUH) said: “Whoever unexpectedly comes across a person suffering a calamity, and says: Al-hamdu Lillahil-ladhi ‘afani mim-mabtalaka bihi, wa faddalani ‘ala kathirin mimman khalaqa tafdila (Praise is to Allah Who has kept me safe from that which has afflicted you and preferred me over many of those whom He has created), will be kept safe from that calamity, no matter what it is.’” Translation Not Available

Book reference: Sunan Ibn Majah Book 34 Hadith 3892
Web reference: Sunan Ibn Majah Volume 5 Book 34 Hadith 3892