Ukraine struck a deal with creditors that could save it more than $11 billion over the next three years, a boost for the war-torn country as it struggles to keep funding the war with Russia .

The preliminary deal, unveiled Monday, came after months of negotiations with a committee representing Western bondholders such as BlackRock and Pimco. The creditors had initially balked over how much relief Ukraine and its Western backers were requesting on nearly $20 billion of international debt run up before the Russian invasion, plus billions more in interest bills.

The rocky path to an agreement showed how the financial industry’s support for Ukraine, unequivocal just after war broke out, had since shifted toward a more pragmatic stance.

Without a deal by the start of August, Ukraine would have faced a default 10 days later, a symbolic blow as it grapples with mounting battlefield losses and waning Western support . Kyiv feared that such a black mark would deter investors from funding any future reconstruction and make it harder to tap lenders such as the International Monetary Fund.

Ukraine

“This allows us to free up resources for our defense, social spending and reconstruction,” said Ukrainian Prime Minister Denys Shmyhal in a post on X.

The committee represents investors holding 22% of the country’s bonds. To finalize the deal, Ukraine needs two-thirds of bondholders to agree to the terms. It hopes to complete the restructuring in the next few weeks, according to a person familiar with the deal.

Repaying foreign creditors will require Ukraine to divert spending from other priorities such as defense. But the interest payments outlined under the deal are workable for Ukraine’s budget, said Olena Bilan, chief economist at the Ukrainian investment bank Dragon Capital .

“For Ukraine, it is better to have the deal now and turn this page,” she said. “This will enable Ukraine to tap the bond market as soon as security risks subside.”

Financial firms rallied around Kyiv at first, offering a sweeping debt holiday and pledging to help secure private capital. When Ukraine moved to start restructuring talks this spring, foreign investors saw an opportunity to recover some lost billions, given that Ukraine is now flush with cash from allies and that its economy grew surprisingly strongly last year.

In June, the creditor group including BlackRock and Pimco rebuffed an earlier Ukrainian proposal and said they wanted $2.5 billion in interest by 2027—nearly four times what Ukraine had offered.

Some investors and others involved in the negotiations described the path to reaching a deal as contentious. Ukraine’s parliament passed a law laying the groundwork for a potential default, raising the stakes in the talks.

Despite the initial differences, an agreement came relatively quickly in comparison to other sovereign-debt restructurings, which can often take years to complete .

In the end, bondholders agreed to write down the face value of their debt by 37%, or about $8.7 billion, and accept lower interest rates and longer maturities.

In return, Ukraine will restart interest payments to private creditors next February and begin repaying principal in 2029. Interest payments will total less than $200 million by the end of 2025. If Ukraine’s economy outperforms, investors could get an extra payment in 2029.

The creditors said they were pleased to offer “significant debt relief to Ukraine, assist its efforts to regain its access to international capital markets, and support the future reconstruction of the country.” The group described the agreement as “swift and constructive.”

Throughout the negotiations, Kyiv’s allies cautioned investors that Ukraine’s resources aren’t for the taking. On a call this month, William Roos, co-chairman of the group of public-sector creditors to Ukraine, told bondholders that anything more than symbolic interest payments would be politically impossible, given that Ukraine’s supporters have funneled more than $100 billion of financial aid to Ukraine since the start of the war, investors familiar with the remarks said.

While lawyers and bankers have spent months debating in New York and London, the situation on the ground has worsened. On the battlefield, Ukrainian forces are outmanned and outgunned . Russian attacks have knocked out half of Ukraine’s electricity-production capacity in recent months, causing rolling blackouts and threatening the economic outlook.

One key advocate for a deal was the IMF, which last year agreed to lend $15.6 billion over four years, its first-ever loan to a country at war. The loan is a fraction of Ukraine’s total Western support, but carries strings that triggered the attempted private-sector debt restructuring.

The Washington, D.C.-based institution often tells states to write down and restructure old debts when they come asking for an emergency loan, to ensure it always gets repaid.

Under an IMF plan, Ukraine has agreed to work with creditors to bring debt down to 65% of gross domestic product by 2033 from nearly 100% now. However, the proposals rest on highly uncertain estimates of Ukraine’s future economic growth and population, the exchange rate and when the war will end.

Some investors asked why the IMF pushed for a debt deal while the war grinds on, given that the country’s fortunes could potentially improve.

Tim Ash of BlueBay Asset Management, another bondholder, was among those who thought creditors should have given Ukraine another debt holiday. “There’s not a good explanation of why there’s been a rush,” Ash said.

—Ian Lovett contributed to this article .

Write to Alexander Saeedy at alexander.saeedy@wsj.com and Chelsey Dulaney at chelsey.dulaney@wsj.com