Abu Hurayrah narrates that the messenger of Allah, Allah send peace and blessings upon him said, whoever sits in a gathering and engages in futile impermissible talk and then recites the following before standing from the gathering, whatever happened in that gathering of his will be forgiven:
Oh Allah! You are pure from imperfection and all praise is due to You, I bear witness that there is none worthy of worship besides You, I seek forgiveness from You and return to You (Your obedience)
Note: This Dua should not only be recited after a futile gathering but also after a gathering in which good was mentioned as in another narration, reported by Imam Nasai the messenger of Allah, Allah be pleased with him mentioned that this supplication is a seal for any good deeds which takes place in a gathering, and expiation for any evil which may have taken place.
حَدَّثَنَا أَبُو عُبَيْدَةَ بْنُ أَبِي السَّفَرِ الكُوفِيُّ وَاسْمُهُ أَحْمَدُ بْنُ عَبْدِ اللهِ الهَمْدَانِيُّ ، قَالَ : حَدَّثَنَا الحَجَّاجُ بْنُ مُحَمَّدٍ ، قَالَ : قَالَ ابْنُ جُرَيْجٍ : أَخْبَرَنِي مُوسَى بْنُ عُقْبَةَ ، عَنْ سُهَيْلِ بْنِ أَبِي صَالِحٍ ، عَنْ أَبِيهِ ،
عَنْ أَبِي هُرَيْرَةَ ، قَالَ : قَالَ رَسُولُ اللهِ صَلَّى اللَّهُ عَلَيْهِ وَسَلَّمَ : مَنْ جَلَسَ فِي مَجْلِسٍ فَكَثُرَ فِيهِ لَغَطُهُ ، فَقَالَ قَبْلَ أَنْ يَقُومَ مِنْ مَجْلِسِهِ ذَلِكَ
سُبْحَانَكَ اللّٰهُمَّ وَبِحَمْدِكَ ، أَشْهَدُ أَنْ لاَ إِلَهَ إِلاَّ أَنْتَ أَسْتَغْفِرُكَ وَأَتُوبُ إِلَيْكَ
إِلاَّ غُفِرَ لَهُ مَا كَانَ فِي مَجْلِسِهِ ذَلِكَ.
(رواه الترمذي: باب ما يقول إذا قام من مجلسه، ح/٣٤٣٣)