The imam recited a verse where a prostration is required and did not prostrate, but the person praying behind him prostrated and missed the rukoo’ (bowing)
If the matter is as described, then your prayer is valid, praise be to Allaah.
The reason for that is that the one who misses bowing with the imam, for a reason like the confusion that you mention, has to do it and then follow the imam, and in that case he is forgiven for his delay in following the imam. If he does not do it, then the rak’ah is invalid, and he has to do it again after the imam says the salaam, and you did that.
It says in Kashshaaf al-Qinaa’ (1/466): If the person praying behind the imam misses an essential part of the prayer for a reason such as sleeping or confusion or because the imam moves too quickly, he should do it and catch up because that is obligatory, because he can catch up with him without any problem, so he has to do that, and the rak’ah will be valid and will count. If he cannot make up what he missed and then catch up with the imam, because that is not possible, then the rak’ah is not valid, rather it is cancelled out because an essential part of it has been omitted. End quote.