President Volodymyr Zelenskiy hailed as "superheroes" the senior Ukrainian commanders, including those who led the dogged defence of Mariupol, who were freed by Russia as part of an unexpected prisoner swap involving almost 300 people, including foreigners.
Under the terms of the deal, which Turkey helped to broker, 215 Ukrainians - most of whom were captured after the fall of the port city - were released on Wednesday. In exchange, Ukraine sent back 55 Russians and pro-Moscow Ukrainians.
Ten foreigners were also freed following mediation by Saudi Crown Prince Mohammed bin Salman, who has maintained close ties with Russian President Vladimir Putin.
"Five superheroes have been exchanged for 55 of those who deserve neither compassion nor pity," Zelenskiy said in a night-time address that welcomed the broader release as "a victory for the country".
The timing and size of the swap came as a surprise. Earlier in the day Putin had announced a partial troop mobilisation in Russia in an apparent escalation of the conflict that began in February. Pro-Russian separatists had said last month that the Mariupol commanders would go on trial.
There was no immediate comment from Moscow about the deal.
Ukrainians cheered the swap.
"We live for the soldiers. They are our pride, our glory, our joy – our boys. I only hope everyone can be freed. And that our mother-Ukraine is freed too," 55-year-old Kyiv resident Tamara Herasymenko said.
The five senior commanders freed include Lieutenant Colonel Denys Prokopenko, and his deputy, Svyatoslav Palamar, both of the Azov battalion, which did much of the fighting in Mariupol and is lionised in Ukraine.
Also freed was Serhiy Volynsky, commander of the 36th Marine Brigade, who in April issued a video message from where fighters were holed up in bunkers below the vast steel works in Mariupol. "This is our appeal to the world. It may be our last. We may have only a few days or hours left," he said at that time.
The three men had helped lead the weeks-long resistance before they and hundreds of Azov fighters surrendered in May to Russian-backed forces.
Zelenskiy held a video call with the men after their release from captivity.
The five commanders will stay in Turkey until the end of the war, and Zelenskiy thanked Turkish President Tayyip Erdogan for his help after what he said had been a long and difficult fight to secure their release.
The Azov Regiment is reviled by Putin's Kremlin as a band of Russia-hating neo-Nazis. The battalion denies allegations of fascism, Nazism and racism and says that Ukrainians from various backgrounds serve in Azov, which is now fully integrated into Ukraine's armed forces.
The eventual capture of Mariupol, on the Sea of Azov, was a big strategic prize for Russia, though its forces had reduced the port city to a wasteland littered with bodies after nearly two months of siege and heavy bombardment.
It meant Russia had a secure overland route linking the Crimean peninsula, which Moscow annexed in 2014, with mainland Russia and parts of eastern Ukraine already held by separatists.
The foreigners released included two Britons and a Moroccan who had been sentenced to death in June after being captured fighting for Ukraine. Also freed were three other Britons, two Americans, a Croatian, and a Swedish national.
Among those released by Ukraine were Viktor Medvedchuk, the leader of a banned pro-Russian party who was facing treason charges.
Riyadh brokered an arrangement whereby the 10 foreigners were flown to Saudi Arabia.
The freed U.S. citizens were Alexander Drueke, 39, and Andy Huynh, 27, both from Alabama, who were captured in June while fighting in eastern Ukraine.
Britons Aiden Aslin and Shaun Pinner and Moroccan Brahim Saadoun had been sentenced to death by a court in the self-proclaimed Donetsk People's Republic.