Praise be to Allah.
He should complete the janaazah prayer and recite the three takbeers to make up what he has missed before the coffin is taken away, then he should say the salaam. The part of the prayer where he caught up with the imaam is considered to be the first part of his prayer, and it is sufficient for him to say the minimum of what is required after the second and third takbeers. After the second takbeer he may say, “Allaahumma salli ‘ala Muhammad (O Allaah, send blessings upon Muhammad)” and after the third takbeer he should say, “Allaahumma ighfir lahu (O Allaah, have mercy on him).” And he should say salaam after the fourth takbeer.
And Allaah is the Source of strength. May Allaah bless our Prophet Muhammad and his family and companions, and grant them peace.