Germany's ruling coalition struck a 2025 budget deal Friday after tough talks that nearly toppled the government, with Chancellor Olaf Scholz vowing the country would remain an "anchor of stability" in Europe.

The budget crisis was one of the most serious to shake the uneasy three-party alliance since it took power in 2021, with supporters of austerity facing off against those calling for greater spending during weeks of tense talks.

A collapse of the centre-left-led government could have had dramatic consequences -- for Europe's most populous country and across the continent -- just weeks after the far right made gains in European elections.

With the stakes so high, Scholz's Social Democrats and their coalition partners, the Greens and the pro-business FDP, finally reached a compromise deal early Friday after a final, marathon round of talks that ran through the night.

"We do not always make it easy for ourselves," admitted Scholz at a press conference following the agreement.

But he added the parties had worked hard to reach compromises, as "the alternative is no alternative: losing your nerve, throwing in the towel or running away from responsibility."

"Germany must now be an anchor of stability" for Europe, Scholz said. "We must not turn away from the world in these times, we must not be preoccupied with ourselves".

Speaking alongside him, Economy Minister Robert Habeck from the Greens said the coalition felt a duty to keep Germany stable in "turbulent times", and it must be a "place of reliability on the European continent and perhaps beyond".

He referred to elections in France, which is holding a decisive round of parliamentary elections Sunday after the far-right National Rally won the most votes the first round, and in the United States where Donald Trump is leading in the polls to return as president.

- 'Political mistake' -

The budget talks went on for weeks, with Scholz, Habeck and Finance Minister Christian Lindner from the FDP meeting 23 times for 80 hours to hammer out a deal.

Pressure mounted on the parties to reach a compromise after they fared poorly at last month's European Parliament elections and the far-right AfD finished in second place.

Central to the budget row were demands from Lindner, a fiscal hawk, for close to 30 billion euros ($32 billion) in savings -- a proposal baulked at by the Greens and SPD.

As part of the agreement, the parties agreed to a key demand of Lindner's -- to stick to the constitutionally enshrined "debt brake", a self-imposed cap on annual borrowing.

It was suspended for several years during the coronavirus pandemic and energy shock trigged by the Ukraine war but Lindner was keen to see it reinstated.

Debate over the rules became more heated after the country's top court ruled in November that the coalition had contravened them by shifting money to special funds outside the main budget.

This led to greater spending constraints in the 2025 budget and prompted calls for the rules to be dropped or loosened to make high-priority investments in the armed forces and decarbonisation.

The budget deal also included measures aimed at boosting Europe's top economy, which has performed poorly in recent times.

The measures such as tax breaks for working pensioners and efforts to reduce bureaucracy are expected to boost growth by about 0.5 percentage points in the coming year.

Germany has been seeking to modernise its military since Russia's invasion of Ukraine, and Lindner said the country should reach military alliance NATO's goal of spending two percent of GDP on defence in 2025.

The defence budget is set to rise to 80 billion euros a year by 2028.

The budget was approved later than initially planned due to the protracted wrangling.

The DIW economic institute said the package showed how the coalition parties had worked hard to "find a constructive solution and overcome their differences".

But the final result was a "restrictive fiscal policy", which would be "one of biggest brakes on economic recovery and is therefore a serious political mistake".

jpl-sr/hmn/gv