All perfect praise be to Allah, The Lord of the worlds. I testify that there is none worthy of worship except Allah and that Muhammad is His slave and Messenger.
In the situation that you mentioned, if you realized that you acted differently from the imaam and you prostrated while the imaam was bowing, then you should have stood up and bowed and then raised from the bowing and then follow the imaam in the prayer.
Shaykh Ibn ‘Uthaymeen said:
“The second case: the questioner says: the imaam recited {And We already know that your breast is constrained by what they say. So exalt [Allah] with praise of your Lord and be of those who prostrate [to Him]. And worship your Lord until there comes to you the certainty (death).} [Quran 15:97-99]; then he said ‘Allahu Akbar’. The person led in prayer thought that the imaam prostrated; why? Because he recited {…and be of those who prostrate}; but the imaam only bowed, and when he said, ‘Sami’a Allahu liman hamidah’ [which is said after raising from the Rukoo’], the person led in prayer realized his mistake; what should he do? Answer: He should perform Rukoo’ and then follow his imaam, because the person led in prayer here did not follow the imaam for an excuse, so he is pardoned, and he was able to follow the imaam in the rest of his prayer.”
As regards whoever did not perform Rukoo’ and followed the imaam in his prayer out of ignorance of the ruling, then that Rak’ah (unit of prayer) is void, and he was obliged to make up for it with another Rak’ah after the imaam concluded the prayer with the greeting of Salaam. The mistake that you (those praying behind him) made is borne by the imaam, and if anyone of you did not perform the Rukoo’ or did not make another Rak’ah after he imaam concluded the prayer with Salaam, then that person must repeat that prayer, as he did not fulfill one of its pillars.
Allah knows best.