LYMAN, Ukraine—Ukraine is going on the defensive.

A costly, monthslong campaign aimed at driving back invading Russian forces has culminated with little shift in the front lines. Economic and military support from the U.S. and Europe are suddenly in doubt. And domestic political fissures are widening as the nation’s morale sags.

Kyiv’s forces are now digging in for what could be an extended period of just trying to stop any more Russian advances. Western diplomats and military strategists say a depleted Ukraine needs time to rebuild, and that it may not be able to mount another significant counteroffensive until 2025.

President Volodymyr Zelensky last week ordered the construction of an extensive network of battlefield fortifications to help troops hold the line. On Armed Forces Day on Dec. 6, Zelensky acknowledged the difficulty of the fight to regain occupied territories but urged perseverance. “Is there really an alternative? No,” he said in a video address.

A Ukrainian soldier gives water to a captured Russian army serviceman, according to them, on a position recently gained in offensive, as Russia’s attack on Ukraine continues, near the front line city of Bakhmut, in Donetsk region, Ukraine May 11, 2023. Radio Free Europe/Radio Liberty/Serhii Nuzhnenko via REUTERS TPX IMAGES OF THE DAY

Local residents remove debris next to their neighbour’s house, heavily damaged by a Russian missile strike, amid Russia’s attack on Ukraine, in Kyiv, Ukraine December 11, 2023. REUTERS/Valentyn Ogirenko

It is a sharp shift in sentiment from earlier this year when Kyiv—buoyed by successes rolling back earlier Russian advances and with an infusion of Western arms—set out to eject Russian troops from the nearly 20% of Ukrainian territory they occupied. Ukraine’s allies hoped it could inflict sufficient damage on Russian forces that President Vladimir Putin would see the war as futile and acquiesce to negotiations acceptable to Kyiv.

The operation foundered against Russian defensive fortifications built over months. Since then, U.S. political unity over Ukraine has ebbed amid partisan disputes, while war between Israel and Palestinians in the Gaza Strip has claimed world attention.

Ukraine’s ability to regain much more of its territory is now in doubt, while Putin’s reorientation of his economy to a war footing has strengthened his hand on the battlefield and, more recently, diplomatically.

Western leaders, meanwhile, have swung from pledging victory on Ukraine’s terms to simply keeping it in the fight. The White House said Monday that the U.S. will be unable to continue providing weapons and equipment to Ukraine if Congress doesn’t pass new funding measures this month.

Stopping U.S. supplies “will kneecap Ukraine on the battlefield, not only putting at risk the gains Ukraine has made, but increasing the likelihood of Russian military victories,” White House Office of Management and Budget Director Shalanda Young wrote to House Speaker Mike Johnson (R., La.).

Congress, rather than heed the warning and approve new aid, this week sank deeper into a partisan fight linking Ukraine assistance to paying for more U.S. border enforcement.

Members of the Siberian Battalion of the Ukraine’s Armed Forces International Legion attend military exercises, amid Russia’s attack on Ukraine, at an undisclosed location in Kyiv region, Ukraine December 13, 2023. REUTERS/Valentyn Ogirenko

The U.S. funding fight is deepening just as European countries are struggling to secure fresh aid for Kyiv. An expected European Union support package for Ukraine’s national budget, valued at roughly $54 billion, likely faces delay or cuts when EU leaders meet next week. The EU is unlikely to agree on any military assistance package before year-end.

In Kyiv, sniping between Zelensky and his top general has increased as military fortunes darkened. More recently, a feud between Zelensky and his predecessor, Petro Poroshenko, showed signs of flaring again after staying restrained since Russia’s large-scale invasion almost two years ago.

On the battlefield, some Ukrainian troops are husbanding ammunition, unsure how long supplies will last. Soldiers fighting in the Donbas area say that rationing artillery shells makes it difficult to hobble Russian units bearing down on them.

Russia, meanwhile, has caught up to Ukraine in drone warfare, a domain where Kyiv’s forces previously held an edge. Ukrainian troops also say Russians have better antidrone and electronic-warfare capabilities, which impede use of drones and Western-supplied precision weaponry.

Adding to pressure on Ukraine, Russia shows no sign of abandoning its original war aim of taking over the country.

Ukrainian Foreign Minister Dmytro Kuleba said that new counteroffensive operations were being prepared. PHOTO: SVET JACQUELINE FOR THE WALL STREET JOURNAL

Ukrainian Foreign Minister Dmytro Kuleba said in an interview that any pause in fighting now would simply grant Russia a chance to regroup and prepare for fresh military action.

“The only outcome would be Russia shaking off the losses and the troubles it faced in Ukraine and making another assault,” he said. “We are setting our brigades for new counteroffensive and defensive operations.”

Some of those defensive operations were evident recently on a hilltop overlooking forested plains near the small eastern city of Lyman. About 12 miles from the front line, two civilian workmen operating industrial excavators sliced trenches into the chalky earth.

The men and others have been digging relatively shallow trenches across the region since Russia’s invasion last year. The Lyman hilltop, which offers a strong defensive position from which to survey the surrounding area and target approaching Russians, was new ground for the excavators.

Their fresh trenches, each about one-third of a mile long, 5 feet wide and over 6 feet deep—or big enough to protect a significant number of troops—mark a new approach for Ukraine’s military. Since the war’s early days last year, Kyiv’s skirmishing troops have striven to mount mobile defensive operations, staging hit-and-run attacks on Russian troops.

The trenches hark back to the stalemate that held along eastern Ukraine’s Donbas area for eight years after its seizure in 2014 by Russian-backed separatists. The new design also more closely mirrors trenches that Russian forces dug starting last winter across Ukraine’s south, which helped thwart Ukraine’s counteroffensive this summer.

At a Ukrainian trench near Lyman, several miles off the front, artillerymen said that they believed Russians dig deep, well-fortified defensive trenches, and do it quickly

“The Russians are definitely good engineers,” said one brigade member.

Military analysts say that shifting to a stationary, defensive position doesn’t mean the war is over. At a recent meeting of North Atlantic Treaty Organization foreign ministers in Brussels, some NATO diplomats reflected that during the war’s early days last year, most observers expected a long fight. After Ukraine scored fast gains last fall, retaking significant territory, hopes of a speedier resolution rose.

“Now we have to remind ourselves that this will be a long war,” said a European diplomat.

Defensive operations, such as those Kuleba cited, may not only include fixed fortifications such as trenches. Throughout the war, Kyiv’s troops have conducted mobile defenses, hitting Russian troops and supplies while they attempt to cross rivers or advance on land or by air.

Ukraine’s Western backers have worked to put a brave face on Kyiv’s shifting fortunes, highlighting its successes on the Black Sea and elsewhere.

“Yes, we haven’t seen significant changes in the front lines over the last months. But there is intense fighting going on,” said NATO Secretary-General Jens Stoltenberg at the foreign ministers’ gathering.

“Military achievements can be measured in many different ways,” he said. Last year’s recovery of territory “was a big gain.”

Other Ukrainian achievements include its deep strikes into Russian territory that have destroyed fighter aircraft and warships, forcing its Black Sea Fleet to remain anchored far from Ukraine and allowing Kyiv more freely to export grain, he said.

“That’s a huge gain that cannot be measured in square meters, but is measured in destroying Russian capabilities,” Stoltenberg said.

A few days later, though, Stoltenberg noted that wars go in phases. “We have to be prepared also for bad news,” he told German broadcaster ARD.

Ukrainians, in recent conversations along the front lines and far away, expressed resignation that more bad news was likely.

If Ukraine and its allies can work through their current adversities and continue delivering supplies to troops, an emerging best-case scenario among Western strategists is that next year becomes a year of rebuilding for Kyiv’s military. The hope would be that a limited number of Ukrainian soldiers can hold Russian forces at bay, allowing NATO countries time to train fresh Ukrainian troops, expand armament production and restock Ukraine’s arsenals.

Another hope expressed at the recent NATO meeting was that Russia’s attempts to break Ukrainian defenses fail, eroding its resources—both manpower and ammunition—and potentially offering Ukraine better prospects to retake the battlefield initiative in the spring of 2025, if it gets through next year.

For now, Ukrainian troops are settling in for what could be a long winter after the first big snows recently. On front-line positions in the Kreminna Forest, east of Lyman, members of the Azov Brigade of Ukraine’s National Guard said that morale is high, but they talked of lost comrades. Few seemed under any illusion that the counteroffensive was successful.

One infantry sergeant said that when he talks to people at home he tells them everything is going well and doesn’t describe what he sees or feels, which isn’t so upbeat.

“What is the point?” he said.

—James Marson and Ievgeniia Sivorka contributed to this article.

Write to Daniel Michaels at Dan.Michaels@wsj.com and Alistair MacDonald at Alistair.Macdonald@wsj.com