By Natalia Zinets

KYIV/NOVOAZOVSK, Ukraine (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 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 announcing evacuations.

"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 said 53 injured troops from the Azovstal steelworks were taken to a hospital in the Russian-controlled town of Novoazovsk, some 32 kilometres (20 miles) to the east.

Another 211 people were taken to the town of Olenivka, in an area controlled by Russian-backed separatists, Deputy Defence Minister Anna Malyar said. All of the evacuees will be subject to a potential prisoner exchange with Russia, she added.

It was not clear how many troops remained in Azovstal. Ukraine's military said efforts were under way to evacuate those still inside.

Reuters saw five buses carrying troops from Azovstal arrive in Novoazovsk late on Monday. Some of the evacuated troops were wounded and carried out of the buses on stretchers. Some 600 troops were believed to have been inside the steel plant.

"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."

Arriving in Novoazovsk in a bus marked with Z, a symbol for Russia's invasion, men could be seen stacked on stretchers on three levels. They stared out the windows without reacting. One man was wheeled out, his head tightly wrapped in thick bandages.

Since Russia launched its invasion in February, Mariupol's devastation has become a symbol both of Ukraine's resistance and of Russia's willingness to devastate Ukrainian cities that hold out.

The first evacuations late on Monday came hours after Russia said it had agreed to evacuate wounded Ukrainian soldiers to a medical facility in Novoazovsk.

LVIV EXPLOSIONS, KHARKIV FIGHTING

Moscow calls its nearly three-month-old invasion a "special military operation" to rid Ukraine of fascists, an assertion Kyiv and its Western allies say is a baseless pretext for an unprovoked war.

Russia's invading forces have run into apparent setbacks, with troops forced out of the north and the environs of Kyiv in late March. A Ukrainian counterattack in recent days has driven Russian forces out of the area near Kharkiv, the biggest city in the east.

Areas around Kyiv and the western city of Lviv, near the Polish border, have continued to come under Russian attack. A series of explosions struck Lviv early on Tuesday, a Reuters witness said. There were no immediate reports of casualties or damage.

On Monday, Ukraine's defence ministry troops had advanced all the way to the Russian border, about 40 km north of Kharkiv.

The successes near Kharkiv could let Ukraine attack supply lines for Russia's main offensive, grinding on further south in the Donbas region, where Moscow has been launching mass assaults for a month yet achieving only small gains.

PUTIN CLIMBDOWN OVER NATO

Russian President Vladimir Putin appeared on Monday to climb down from threats to retaliate against Sweden and Finland for announcing plans to join the U.S.-led NATO military alliance.

"As far as expansion goes, including new members Finland and Sweden, Russia has no problems with these states - none. And so in this sense there is no immediate threat to Russia from an expansion to include these countries," Putin said.

The comments appeared to mark a major shift in rhetoric, after years of casting NATO enlargement as a direct threat to Russia's security, including citing it as a justification for the invasion of Ukraine itself.

Soon before Putin spoke, Russia's deputy foreign minister, Sergei Ryabkov, said Finland and Sweden were making a mistake that would have far-reaching consequences: "They should have no illusions that we will simply put up with it."

Putin said NATO enlargement was being used by the United States in an "aggressive" way to aggravate an already difficult global security situation, and that Russia would respond if the alliance moves weapons or troops forward.

"The expansion of military infrastructure into this territory would certainly provoke our response. What that (response) will be - we will see what threats are created for us," Putin said.

Finland and Sweden, both non-aligned throughout the Cold War, say they now want the protection offered by NATO's treaty, under which an attack on any member is an attack on all.

"We are leaving one era behind us and entering a new one," Swedish Prime Minister Magdalena Andersson said, announcing plans to formally abandon militarily non-aligned status - a cornerstone of national identity for more than 200 years.

(Reporting by Natalia Zinets in Kyiv and a Reuters journalist in Novoazovsk; Additional reporting by Reuters bureaux; Writing by Rami Ayyub; Editing by Cynthia Osterman)