What to do when it is late for prayer? What happens at the end of the prayer?
It is haram for anyone to start the prayer after the employed imam of the masjid has read the qamat. If the qamat is recited for the employed imam of the masjid after the person has started praying, they will stop and follow the imam. If there is a possibility of missing one rakah of the salat to be performed with the imam while they are trying to complete their salat, they will leave their salat and they will start following the imam. But if the person does not fear that this will happen, he will complete his salat.
Source: Fiqh1 (According To The Maliki School Of Islamic Law), Erkam Publications