If the imam must leave during the salah due to some reason, for instance, he remembers that he is in need of making ablution or he loses his ablution during the salah, then he should appoint another to lead the remainder of the prayer.
‘Amr ibn Maimun says: “I was standing and there was no one between me and ‘Umar, the morning he was killed, except ‘Abullah ibn ‘Abbas. He had barely pronounced the takbir when he was stabbed and he said: ‘The dog has bitten or killed me.’ ‘Umar bade ‘Abdur Rahman ibn ‘Auf to lead the salah and he led them in a short prayer.” This is related by al-Bukhari.
Abu Razin reports: “‘Ali was praying one day when his nose began to bleed. He took a man by the hand and put him in front of the congregation, and he left.” This is related by Sa’id ibn Mansur.
Ahmad observes: “If the imam appoints another [it is acceptable] as ‘Umar and ‘Ali appointed another. If the people pray individually, [it is acceptable] as in the case of Mu’awiyyah when he was stabbed and the people prayed individually and completed their prayers.”