KYIV, May 17 (Reuters) - Ukraine's military said on Tuesday it was working to evacuate all remaining troops from their last stronghold in the besieged port of Mariupol, ceding control of the city to Russia after months of bombardment.

The evacuation of hundreds of fighters, many wounded, to Russian-held towns, likely marked the end of the longest and bloodiest battle of the Ukraine war and a significant defeat for Ukraine. Mariupol is now in ruins after a Russian siege that Ukraine says killed tens of thousands of people in the city.

With the rest of Mariupol firmly in Russian hands, hundreds of Ukrainian troops and civilians had holed up beneath the city's Azovstal steelworks. Civilians inside were evacuated in recent weeks, and more than 260 troops, some of them wounded, left the plant for Russian-controlled areas late on Monday.

"The 'Mariupol' garrison has fulfilled its combat mission," the General Staff of Ukraine's Armed Forces said in a statement.

"The supreme military command ordered the commanders of the units stationed at Azovstal to save the lives of the personnel... Defenders of Mariupol are the heroes of our time," it added.

Ukraine's Deputy Defence Minister Anna Malyar said 53 injured troops from steelworks were taken to a hospital in the Russian-controlled town of Novoazovsk, some 32 km (20 miles) to the east, while another 211 people were taken to the town of Olenivka, in an area controlled by Russian-backed separatists.

All of the evacuees will be subject to a potential prisoner exchange with Russia, she added.

Some 600 troops were believed to have been inside the steel plant. Ukraine's military said efforts were under way to evacuate those still inside.

"We hope that we will be able to save the lives of our guys," Ukraine President Volodymyr Zelenskiy said in an early morning address. "There are severely wounded ones among them. They're receiving care. Ukraine needs Ukrainian heroes alive."

Reuters saw five buses carrying troops from Azovstal arrive in Novoazovsk late on Monday. In one, marked with Z - a symbol for Russia's invasion - men were stacked on stretchers on three levels. One man was wheeled out, his head tightly wrapped in thick bandages.