In Maraatib al-Ijmaa' p 48, Aboo Muhammad ibn Hazm said, "The scholars had a consensus that whoever misses a smaller part or greater part of the prayer such that when he enters the mosque, the only remaining part of the prayer will be the tasleem should join the congregation, and follow that stage of prayer if he is certain that he will not catch up with the congregational prayer in other mosques.
من جاء آخر الصلاة وجب عليه الدخول مع الإمام