Making salaam before fulfilling of a missed rakaat

Q: I joined the jamaat after missing one rakaat. When the Imam made salaam at the end of
the salaah, by mistake I also made salaam. Realising my mistake, I immediately stood up. I
had turned my head completely when making the salaam. I then proceeded to fill in the
missed rakaat. Was my salaah valid?
A: Your salaah was valid but you had to make sajda sahu for that error.