The news ended "months of uncertainty and suffering for them and their families", Ms Truss said.
Aiden Aslin and John Harding who were captured while fighting with Ukraine forces were among the Britons released.
Ms Aslin's local MP Robert Jenrick said in a tweet: "Aiden's return brings to an end months of agonising uncertainty for Aiden's loving family in Newark who suffered every day of Aiden's sham trial but never lost hope. As they are united as a family once more, they can finally be at peace."
He had been held with Shaun Pinner, 48, from Bedfordshire, while fighting in the south-eastern city of Mariupol.
Both men had been put on trial in the self-declared Donetsk People's Republic and told they faced the death sentence.
Mr Harding from Sunderland was one of several others who were awaiting trial.
A British man providing humanitarian assistance in Ukraine, Dylan Healy, is also known to have been held by Russian-backed forces.
In a statement, Saudi Arabia said Moroccan, US, Swedish and Croatian nationals had also been freed as "part of an exchange of POWs between Russia and Ukraine".
Ms Truss thanked Ukrainian president Volodymyr Zelensky "for his efforts to secure the release of detainees, and Saudi Arabia for their assistance".
She added: "Russia must end the ruthless exploitation of prisoners of war and civilian detainees for political ends."
Details about the British nationals and the process that led to their release were not released by the UK government.