Praise be to Allah.
Your prayer is valid, as is the prayer of those who were praying behind you, because they were not aware of their imam’s situation, and they believed that his prayer was valid, as in the case of one who prayed behind an imam then they found out that he was in a state of impurity.
The fact that you interrupted your prayer then resumed leading them in prayer does not matter, because if the imam’s prayer becomes invalid, it is permissible for the members of the congregation to complete their prayer individually, or for someone to step forward and lead them in prayer.
By the same token, if the regular imam is late for the prayer and the people appoint one of their number to lead them in prayer, it is permissible for the regular imam to go forward to lead the people in prayer (when he arrives), and for the imam who had started leading them in prayer to step back and join the congregation, as the Prophet (blessings and peace of Allah be upon him) did when Abu Bakr led the people in prayer. Al-Bukhari (368) and Muslim (418) narrated that ‘A’ishah (may Allah be pleased with her) said: The Messenger of Allah (blessings and peace of Allah be upon him) instructed Abu Bakr to lead the people in prayer, when he was sick, so he used to lead them in prayer. ‘Urwah said: Then the Messenger of Allah (blessings and peace of Allah be upon him) began to feel a little better, so he came out and saw Abu Bakr leading the people in prayer. When Abu Bakr saw him, he stepped back, but he gestured to him to stay where he was. Then the Messenger of Allah (blessings and peace of Allah be upon him) sat down beside Abu Bakr, then Abu Bakr followed the prayer of the Messenger of Allah (blessings and peace of Allah be upon him) and the people followed the prayer of Abu Bakr.
If the imam realises that he did not intend to offer the obligatory prayer, then he should interrupt his prayer and inform the congregation about that, so that he and they can start the prayer all over again. He should not feel too embarrassed to do that, because forgetfulness is a human characteristic and even the best of humanity, the Prophet (blessings and peace of Allah be upon him), made mistakes in his prayer. But if he fears that it will cause confusion to the worshippers, there is nothing wrong – in that case – with him asking one of the worshippers to step forward and lead the people in completing the prayer, and he may step back and join the congregation, and start the prayer all over again behind this (new) imam.
And Allah knows best.