Sayyida Umm Salamah (may Allah be pleased with her) says that the Prophet (peace and blessings be upon him) said: "When you attend the funeral of a deceased person, the angels also say Ameen." I said: O Messenger of Allah! What should we say? The Prophet (peace and blessings be upon him) said: "Say: ﴿اللّٰهُمَّ اغْفِرْ لَنَا وَلَهُ وَارْحَمْهُ وَاعْقُبْنِي مِنْهُ عُقْبَى صَالِحَةً﴾ 'O Allah! Forgive us and him, have mercy on him, and grant me in his place a good substitute.'" So Allah Almighty granted me, in exchange for him, the Prophet (peace and blessings be upon him).
Related hadith on this topic