KYIV, Ukraine—Ukrainian President Volodymyr Zelensky said the eastern city of Lyman had been cleared of Russian forces and that Ukrainian flags were flying again, scoring a symbolic military and political victory against Moscow on the very territory President Vladimir Putin said last week Russia would annex.

Russia’s Defense Ministry said it was withdrawing troops from the city following days of advances by Ukrainian forces to surround them, but Moscow kept several thousand troops there, most likely encircled until fighting ended.

“Lyman is cleared completely,” Mr. Zelensky said in a short address to Ukrainians at midday local time on Sunday, shortly after announcing that “the Ukrainian flag is already in Lyman, Donetsk region.”

Kyiv’s victories since the start of September have shifted the battlefield momentum in favor of Ukraine for the first time since the start of Russia’s invasion earlier this year and since Moscow-controlled separatists picked up arms in 2014 to create pro-Moscow statelets in eastern Ukraine.

Ukrainian advances have unsettled Russian lines of defense in eastern Ukraine. Kyiv’s forces have been chipping away at Russian positions for several weeks there as well as in the country’s south where Ukraine is slowly taking back land with the aim of driving the Russians out of the strategically important city of Kherson on the Dnipro River.

Ukrainian soldiers shot a video in front of the city hall in Lyman over the weekend, celebrating their control over the city, with one of them holding a Ukrainian flag on top of the building and a Russia-occupation flag on the ground.

Roads to Lyman were lined with burned-out hulks of Russian tanks and armored vehicles, with bodies of Russian soldiers lying on the sides. Little remains of nearby villages, with hardly any civilians left. Ukrainian forces, too, have been taking significant casualties.

A church damaged during fighting in Sviatohirsk, in eastern Ukraine’s Donetsk region.

Photo: STRINGER/REUTERS

Russia’s military setbacks—and the prospect of further lost territories—have raised fears that the Kremlin may resort to nuclear weapons to achieve what it has failed to do with conventional forces. Security analysts say that though the threat of a nuclear strike is higher now than it has been since the Cold War, Russia doesn’t appear poised to deploy one imminently.

In Moscow, Russia’s government was focusing on the formalities around absorbing the Ukrainian territories despite the battlefield setbacks. On Sunday, the country’s Constitutional Court approved integration of the occupied regions. The speaker of Russia’s Duma, or lower house of parliament, said the legislative body would consider laws on the admission of the Ukrainian territories into the Russian Federation on Monday.

Mr. Zelensky said Mr. Putin’s announcement Friday to absorb four regions of eastern and southern Ukraine—Donetsk, Luhansk, Zaporizhzhia and Kherson, where Russian troops occupy varying amounts of territory—had backfired for the Kremlin leader. The Ukrainian leader said mounting battlefield losses were causing Russia’s military and political leadership to turn on itself in the hunt for culprits.

“They have already started biting each other there,” Mr. Zelensky said. “They are looking for the culprits, accusing some generals of failures.”

Russian officials and military commentators have cried for Ukraine to pay for a string of defeats they have inflicted on Russia’s armed forces in the past month, starting with a breakthrough offensive in northeastern Ukraine that in a matter of days delivered Kyiv swaths of Ukrainian territory that Russia had spent months fighting to gain earlier in the summer.

Ramzan Kadyrov, the leader of the predominantly Muslim Russian region of Chechnya, whose own forces are fighting in Ukraine against Kyiv and who has butted heads with the Russian Defense Ministry, urged the firing of Col. Gen. Aleksandr Lapin, commander of Russia’s Central Military District, who oversaw the Lyman area. He also called for harsher measures to execute victories for the Russian military, including a tactical nuclear strike

The formal process of integrating the Ukrainian regions into the territory of Russia has handed Mr. Putin a veneer of victory in a war where his troops have stumbled time and time again. But the Kremlin leader’s promise to defend Russia, including the new territories, with “all weapons at our disposal” has raised fears that Moscow could cross the nuclear threshold to protect its gains against increasingly successful Ukrainian advances.

In the Vatican, Pope Francis appealed directly to Mr. Putin to end the “spiral of violence and death,” and warned that the annexations made nuclear war more likely.

The movement on the battlefield came as Gazprom, the Russian state gas giant, severed supplies to Italy, saying it was unable to transport gas because of an administrative issue with an Austrian operator.

The U.K. Ministry of Defense said Lyman was likely being defended by undermanned elements of Russia’s Western and Central Military Districts as well as contingents of voluntarily mobilized reservists.

Elsewhere in the Donetsk region, Ukrainian soldiers work on a howitzer near the city of Siversk.

Photo: Inna Varenytsia/Associated Press

“Lyman…commands a key road crossing over the Siversky Donets River, behind which Russia has been attempting to consolidate its defenses,” the Defense Ministry said in a statement.

Russian military correspondents said that Ukraine would likely try to keep momentum to attack Kreminna to the east, a strategically important point that could put Ukraine’s forces within range to advance on the Russian stronghold of Severodonetsk, which Moscow captured after a weekslong grinding artillery advance, losing men and ammunition.

Russia’s Defense Ministry didn’t respond to the Ukrainian claims, but on Sunday posted videos of soldiers conducting exercises with newly mobilized forces. It said it was continuing attacks on Kupyansk which Ukrainian forces had captured in its breakthrough offensive in Kharkiv region.

Write to Thomas Grove at thomas.grove@wsj.com