LVIV, Ukraine — The Ukrainian military said Wednesday that it was ordering the last of its forces to retreat from the ruins of Vuhledar, a mining town that had served as a vital defensive bastion for nearly three years in eastern Ukraine, after it was stormed by Russian troops.

Ukrainian soldiers fighting in Vuhledar said they had already been largely forced out, and combat footage geolocated by military analysts showed Russian forces in nearly every corner of the town Tuesday.

The loss of Vuhledar will complicate the defense of the southwestern part of the Donetsk region of eastern Ukraine, allowing Russia to step up attacks in the direction of Pokrovsk, a rail and road hub, soldiers and military analysts said. Pokrovsk is also a gateway to the economically important Dnipro region.

However, it has taken Russia nearly three years to capture the stronghold, and Ukraine still controls more than a third of the Donetsk, including a collection of the region’s largest cities, experts say. There are signs both armies are exhausted after years of fighting, raising questions about Russia’s capacity to exploit its gains as well as Ukraine’s ability to continue fending off relentless attacks.

Russia has been on the offensive for nearly a year, and while the last four months of the war have been the deadliest for Moscow since it launched its invasion in February 2022 — with more than 1,000 soldiers killed and injured every day, according to the British military — it has made steady gains in recent months. Russian forces are pressing up against several other Ukrainian strongholds across the east, and brutal battles have been raging as the defenders try to thwart the onslaught.

While Ukrainian military officials had expressed hope that the pace of attacks would have eased by now, Russia continues to mount headlong assaults in a furious effort to gain as much territory as it can before the expected rains in the fall turn cratered fields into thick mud, hindering the movement of heavy armor.

Ukrainian soldiers described a harrowing effort to escape the town as Russian forces closed in from three sides last week.

Hunted by drones loitering overhead ready to drop grenades, under fire from mortars and rockets, and with the constant threat that a powerful guided bomb will kill them in an instant, soldiers described how the only way out for some was on foot.

“It took us an hour to walk” 550 yards, Maksym, 23, said as he was being evacuated. “On top of that, the battery commander was wounded, and we were dragging him. We pulled him out, gave him aid.”

They were able to get the commander to an armored vehicle for evacuation, but the rest of the soldiers had to wait for nightfall before moving again, he said.

“There was a kilometer of open field ahead that we needed to cross. We nearly made it, 60 meters away from the forest line, and then we got hit,” Maksym said, describing three grenades being dropped. He spoke as he was evacuated last week and asked that only his first name be used in accordance with military protocol.

“Fueled by adrenaline, we ran,” Maksym said. They spotted a trench and dove for cover as another drone dropped more explosives on their positions. They eventually reached the medics, but he said other soldiers were not so fortunate.

The Ukrainian eastern military command said it was issuing the formal order to retreat because of “a threat of encirclement.”

It was not clear how many civilians in the town survived the final battle.

A colonel in a Ukrainian evacuation unit, Artem Shchus, estimated last week that there were around 50 people still trapped in Vuhledar, a fraction of the 14,000 who once lived there.

Taking Vuhledar is likely to ease pressure on Russia’s supply lines across southern Ukraine to Crimea.