WE RELATE FROM the books of at-Tirmidhī and others that Abū Hurayrah
related that the Messenger of Allah
said: “Whoever sits in a gathering in which there is much meaningless chatter and says, before he gets up to leave that gathering: Glory be to You, Allah, and to You be all praise. I bear witness that there is no god but You. I ask You for forgiveness and I repent to You, will be forgiven for all that took place in that gathering.” [1].At-Tirmidhī says that this is a ḥasan ṣaḥīḥ hadith.
Subḥānaka-llāhumma wa bi-ḥamdik. Ashhadu an lā ilāha illā Ant. Astaghfiruka wa atūbu ilayk.
We relate in the Sunans of Abū Dāwūd and others that Abū Barazah
, whose name was Nadalah, narrated: “The last thing that the Messenger of Allah
said when he was about to get up from a gathering was: ‘Glory be to You, Allah, and to You be all praise. I bear witness that there is no god but You. I ask You for forgiveness and I repent to You.’ A man said to him: ‘Messenger of Allah, you have said something that you have never said before.’ He replied: ‘That was an atonement for whatever happened in the gathering.’” [2].Al-Ḥākim in his Mustadrak says of a version from ‘Ā’ishah that the isnād is ṣaḥīḥ.
I say that bi-akharah, ‘last thing’, is written with a short hamzah with a fatḥah and with a fatḥah on the khā’, and means ‘at the end of something’.
It is related in Ḥilyat al-awliyā’ that ‘Alī
said: “Whoever wants his deeds to be judged by a perfect measure should say at the end of a gathering or when he stands up: ‘Glory be to your Lord, Lord of Majesty, above all that they ascribe to Him, and peace be upon the Messengers, and all praise be to Allah, the Lord and Cherisher of the Universe.” [3].

Subḥāna Rabbika Rabbi-l-‘izzati ‘ammā yaṣifūn, wa salāmun ‘ala-l-Mursalīn, wa-l-ḥamdu li-llāhi Rabbi-l-‘ālamīn.
References
[1] An-Nasā’ī in ‘Amal al-yawm wa al-laylah (397), Abū Dāwūd (4858), and at-Tirmidhī (3429), who states that this hadith is ḥasan ṣaḥīḥ gharīb from this line of narration.
[2] Abū Dāwūd (4859) and an-Nasā’ī (426).
[3] Qur’ān 37:180–182. This hadith is reported in al-Futūḥāt (6/170), in Ḥilyat al-awliyā’ in a mawqūf form, and by Ibn Abī Ḥātim in a marfū‘ and a mursal form.