All perfect praise be to Allaah, The Lord of the Worlds. I testify that there is none worthy of worship except Allaah, and that Muhammad is His slave and Messenger.
Indeed you did well by endeavouring [making Ijtihaad, i.e. a judgment based on the best of one’s ability with the information available] to find out the direction of the Qiblah and the Maghrib prayer that you performed based on this Ijtihaad is a valid prayer. That is because if a person performs the prayer to a direction and then after making Ijtihaad it became clear to him that he had certainly prayed to other than the direction of the Qiblah, he is not obliged to repeat the prayer. The same thing applies to the people who follow someone (who is reliable) in facing the Qiblah and pray while doing so.
However, after it had become clear to you during the ‘Isha prayer that you prayed in the opposite direction of the Qiblah, then you should have turned towards the Qiblah. Since you did not do so, then you are obliged to repeat this prayer [‘Isha prayer]. Nonetheless, the people who were led by you in the prayer and they did not know the right direction until the end of the prayer, they are not obliged to repeat the prayer.
For more benefit, please refer to Fataawa 85363 and 86809.
Allaah Knows best.