Abu Huraira reported: The Messenger of Allah, peace and blessings be upon him, said, “Whoever sits in a gathering and indulges in idle talk, then let him say before leaving that gathering, ‘Glory be to You, O Allah, and Your praises. I bear witness there is no God but You, I seek Your forgiveness and repent to You,’ as he will be forgiven for what happened in that gathering of his.”
Source: Sunan al-Tirmidhī 3433
Grade: Sahih (authentic) according to Al-Tirmidhi
عَنْ أَبِي هُرَيْرَةَ قَالَ قَالَ رَسُولُ اللَّهِ صَلَّى اللَّهُ عَلَيْهِ وَسَلَّمَ مَنْ جَلَسَ فِي مَجْلِسٍ فَكَثُرَ فِيهِ لَغَطُهُ فَقَالَ قَبْلَ أَنْ يَقُومَ مِنْ مَجْلِسِهِ ذَلِكَ سُبْحَانَكَ اللَّهُمَّ وَبِحَمْدِكَ أَشْهَدُ أَنْ لَا إِلَهَ إِلَّا أَنْتَ أَسْتَغْفِرُكَ وَأَتُوبُ إِلَيْكَ إِلَّا غُفِرَ لَهُ مَا كَانَ فِي مَجْلِسِهِ ذَلِكَ
3433 سنن الترمذي كتاب الدعوات باب ما يقول إذا قام من المجلس
5/431 المحدث الترمذي خلاصة حكم المحدث حسن صحيح في سنن الترمذي