SLOVYANSK, Ukraine—Maj. Yuriy Bereza’s battalion spent months defending, then retreating from city after city in Ukraine’s east in the face of overwhelming Russian firepower.

Now, with Russia’s offensive stalled after a costly advance, Maj. Bereza’s 1,500 men are digging in, creating a nearly 10-mile line of trenches to defend this strategic city.

“We’re at the point where Russia can no longer advance, and we can’t advance yet,” Maj. Bereza said at a command post of the Dnipro-1 battalion of Ukraine’s National Guard on the outskirts of Slovyansk.

The war in Ukraine’s east has reached a new phase: a violent stalemate. Russia’s troops have been exhausted by grinding offensives and Ukrainian resistance, bolstered in recent weeks by long-range rocket launchers provided by the U.S. The Ukrainians aim to stymie the Russians in the east and probe in the south in search of a breakthrough.

Maj. Yuriy Bereza leads 1,500 men seeking to keep the invading Russian forces at bay.

The soldiers of Dnipro-1 have dug deep as they try to fortify the Ukrainian line.

Russian President Vladimir Putin set the conquest of Ukraine’s eastern Donetsk and Luhansk regions as a central goal of his invasion. His forces captured Lysychansk and Severodonetsk in late June, securing most of Luhansk. Ukrainian and Western officials warned that Slovyansk, a major transport hub in Donetsk that was briefly occupied by Russian irregulars in 2014, would be next.

But two months on, Russia has hardly advanced, and the city with a prewar population of 110,000 stands largely deserted but unbowed. Weary-looking Ukrainian servicemen on breaks from the front line just 5 miles away fill the two cafes still operating, stop for haircuts at its barber shop and take advantage of cellphone connection to call relatives. Shelling rings out in the distance.

“We used to come here once a week if we were lucky,” said a soldier from Vinnytsia in central Ukraine, smoking near the main square with members of his unit on a recent sunny afternoon. “Now we come more often, to check the news and take a couple hours off.”

The city of Slovyansk, a recent target in Russia’s eastern campaign, is mostly deserted.

Ukrainian servicemen take a break from their battle preparations in Slovyansk.

A telegraphed Ukrainian offensive in the south prompted Moscow to move thousands of troops there from the east.

Long-range Himars rocket systems supplied by the U.S. have allowed Ukraine to strike ammunition depots and command posts deep in the rear, complicating Russia’s resupply effort and limiting its ability to concentrate devastating artillery on Ukrainian defensive lines.

SHARE YOUR THOUGHTS

How do you think the next phase of the war in Ukraine will play out? Join the conversation below.

“The war right now is in a transitional phase where Russian forces have lost much of the momentum they previously had and the battlefield appears relatively static,” said Michael Kofman, an expert on the Russian military at CNA, a defense-research organization in Arlington, Va.

The U.S. on Wednesday promised a new military aid package totaling nearly $3 billion, but it didn’t include equipment such as tanks and armored fighting vehicles that Ukraine would need to mount a mechanized advance.

“That it’s become quieter here is a good thing,” said Maj. Bereza, a former lawmaker and veteran of earlier battles against Russian proxy forces since 2014. “But without offensive arms we can’t do anything.”

Maj. Yuriy Bereza consults a map at a base in Slovyansk.

Trenches have become a key part of the Ukrainians’ defenses against Russia’s artillery-heavy tactics.

Inside a bunker close to Russian lines, the 52-year-old monitors the battlefield on a set of screens that link to his iPad and relay images from cameras installed at his battalion’s positions. To his left is an annotated wall map titled Plan for the Defense of Slovyansk. Across the room, a computer processes intercepted Russian communications and feeds them to his troops.

The Dnipro-1 battalion under Mr. Bereza’s command is focusing its energies on entrenching around Slovyansk, Bakhmut and other settlements in Russia’s sights.

“The deeper we dig, the higher our likelihood of staying alive,” said a Dnipro-1 soldier overseeing fortification efforts between Slovyansk and Bakhmut. He tours a labyrinth of trenches that are dug deep into the earth and include rudimentary living quarters complete with shelves holding coffee jars, tinned food and religious icons.

Dnipro-1 soldiers say Russia maintains superiority in firepower and is still capable of dropping tons of shells a day just on Ukrainian positions around Slovyansk.

Soldiers in eastern Ukraine face the task of realizing Kyiv’s pledge to regain territory seized by Russia.

Capt. Serhiy Ivashenko says three members of his unit have died in the past month and a half.

“The situation has become easier but we can’t forget this is a very fragile balance,” said Capt. Serhiy Ivashenko.

During Ukraine’s fight for Rubizhne to the northeast, Capt. Ivashenko says, Russian forces were firing 100 artillery shells for every five discharged by his platoon. “We weren’t even able to poke our heads out of the trenches,” he said.

The Russian tactic of relentless artillery barrages means the Ukrainians don’t even see the enemy, he said.

“They stand at the maximum range that their artillery allows, scorch through 10 kilometers of earth, then move forward 10 and scorch the next 10,” he said. “They fire shells that simply destroy every living thing and every fortification, and it’s thanks to them that they move forward.”

In a message on Ukraine’s Independence Day on Wednesday, President Volodymyr Zelensky repeated a pledge to liberate parts of Ukraine taken by Russian forces, including eastern Ukraine and Crimea.

Natalia Tarasenko visits the grave of her husband, who died earlier this month while fighting for Ukraine.

“If there is going to be another chapter or phase in this war, it’s likely to be driven by Ukrainian actions more so than Russian ones,” said Mr. Kofman. “The main question is what Ukraine is going to do next.”

In the absence of a clear answer, an uneasy equilibrium prevails in Ukraine’s east.

At one of Dnipro-1’s bases north of Slovyansk, black ribbons tied to a metal pole commemorate comrades who have fallen in battle. In the past month and a half, Capt. Ivashenko says, three members of his unit have died.

Local residents are also feeling the toll. Natalia Tarasenko, a resident of nearby Kramatorsk, buried her husband, Vladyslav, last week at a cemetery outside the city where fresh plaques list the names of other fallen soldiers.

Mr. Tarasenko was working at a metal factory when he was called up to join Ukraine’s 81st Airmobile Brigade in late June. He died on Aug. 8 under a hail of Russian artillery near Bohorodychne, north of Slovyansk.

“They say the war has lessened,” Ms. Tarasenko said after she had laid a jar of her husband’s favorite coffee and flowers by his grave. “He is evidence that it hasn’t.”

New graves at a cemetery near Kramatorsk where soldiers and civilians alike have been buried.

Write to Matthew Luxmoore at Matthew.Luxmoore@wsj.com