If somebody is leading the Salat (prayer) and (in the meanwhile) the first (usual) Imam comes, the Salat is valid whether the former retreats or does not retreat
Once Allah's Messenger (ﷺ) went out to answer the call of nature and I followed him with a tumbler containing water, and when he finished, I poured water and he performed ablution and passed wet hands over his Khuffs (socks made from thick fabric or leather).
Reference: Sahih al-Bukhari 203 In-book : Book 4, Hadith 69 USC-MSA web (English) : Vol. 1, Book 4, Hadith 202 (deprecated)
Help us gift a modern, ad-free Islamic application for the Muslim Ummah. Your donation will be recorded as Sadaqah Jariyah in your book of deeds, In Sha Allah.