The prisoners of war, who are citizens of Morocco, the US, the UK, Sweden and Croatia, were released as part of an exchange between Russia and Ukraine, the Saudi Ministry of Foreign Affairs said.
“The relevant Saudi authorities received and transferred them from Russia to the kingdom and are facilitating procedures for their safe return to their respective countries,” the ministry said.
“The Ministry of Foreign Affairs expresses the gratitude and appreciation of the government of the kingdom of Saudi Arabia to the Russian Federation and to Ukraine for their response to the efforts made by the Crown Prince for the release of the PoWs.”
Two US military veterans who disappeared while fighting alongside Ukrainian forces were also part of the prisoner swap announced on Wednesday, their relatives said.
Alex Drueke, 39, and Andy Huynh, 27, went missing after their unit came under heavy fire in the Kharkiv region of north-eastern Ukraine on June 9.
"The United States welcomes the negotiated prisoner exchange between Ukraine and Russia, which includes two US citizens captured while serving in Ukraine’s military," US Secretary of State Antony Blinken said.
"The United States is appreciative of Ukraine including all prisoners of war, regardless of nationality, in its negotiations and we look forward to these US citizens being reunited with their families."
Mr Blinken also expressed his thanks to Saudi Arabia and said he "conveyed his gratitude to Saudi Foreign Minister [Prince] Faisal bin Farhan in a call" on Wednesday.
UK Prime Minister Liz Truss said on Wednesday that five British citizens held by Russian-backed forces in eastern Ukraine were being returned to their families.
“Hugely welcome news that five British nationals held by Russian-backed proxies in eastern Ukraine are being safely returned, ending months of uncertainty and suffering for them and their families,” she wrote on Twitter.
She thanked Ukrainian President Volodymyr Zelenskyy for "his efforts to secure the release of detainees, and Saudi Arabia for their assistance”.
“Russia must end the ruthless exploitation of prisoners of war and civilian detainees for political ends,” Ms Truss said.
The group released on Wednesday also included citizens from Morocco, Sweden and Croatia, a Saudi official said.
The five British prisoners included Aiden Aslin, one of three men captured while fighting for Ukraine and sentenced to death in June.
“I am delighted that my constituent, Aiden Aslin, and the other British prisoners of war held captive by the Russian authorities have finally been released and are on their way back to the UK,” said Nottinghamshire MP Robert Jenrick.
“I am deeply grateful for the work undertaken by the Ukrainian government, the Saudi Crown Prince, Liz Truss, [UK Foreign Secretary] James Cleverly and the dedicated civil servants working in the [Foreign, Commonwealth and Development Office] detainees team to bring their horrific ordeal to a close."
Mr Cleverly welcomed the safe return of the British citizens.
"Prisoners of war from other countries held by Russia-backed proxies have also been returned," he said.
"This brings to an end many months of uncertainty and suffering, including the threat of the death penalty, for them and their families at the hands of Russia.
“Tragically that was not the case for one of those detained and our thoughts remain with the family of Paul Urey."
The announcement comes a day after Russia and Ukraine agreed to swap 200 prisoners in one of the largest exchanges of the seven-month war, Turkish President Recep Tayyip Erdogan told US television.
He made the announcement after talks last week with Russian President Vladimir Putin at a regional conference in Uzbekistan.
Mr Erdogan called the people being exchanged “hostages” and declined to say how many there were from each side.
Prince Mohammed on Tuesday met Rustem Umerov, special envoy of Ukraine’s president, in Jeddah.
”During the meeting, His Royal Highness the Crown Prince affirmed the kingdom's keenness and support for efforts that contribute to de-escalating the crisis in Ukraine, and the kingdom's support for all international efforts to reach a political resolution to the crisis, as well as continuing its efforts to mitigate the humanitarian fallout resulting from it,” the royal court said.