German Chancellor Angela Merkel's conservatives and the Social Democrats sealed a deal on Wednesday on a new coalition, officials said, potentially ending four months of political deadlock in Europe's top economy.
The parties ironed out their final differences and were ready to sign an agreement for Merkel's fourth term, her chief of staff and acting finance minister Peter Altmaier said, calling it a "good day for our country."
"We have a coalition agreement that will do a lot of positive things for a lot of citizens," Altmaier told reporters after he emerged from more than 24 hours of contentious talks.
The breakthrough will come as a relief to Germany's EU partners as the bloc faces tough negotiations on migration and Brexit.
Merkel, Europe's most experienced leader, has seen her standing at home and abroad weakened by the longest stretch of coalition-building in the country's postwar history.
But before she can be sworn in, a final hurdle looms: the hard-fought "grand coalition" pact between her CDU/CSU bloc and the Social Democratic Party must still be approved by the SPD's sceptical rank-and-file.
Germany has been stuck in political limbo since September's inconclusive general election saw mainstream parties bleed support to the far-right AfD, which tapped into anger over Merkel's liberal refugee policy.
Merkel, in power for over 12 years, at first tried to cobble together a novel three-way coalition with the Greens and the liberal Free Democrats, but those efforts collapsed in November.
Faced with snap elections that could further boost the AfD or the prospect of heading an unstable minority government, she opted to woo back the SPD -- her junior partner for two of her three terms since 2005.
SPD leader Martin Schulz then abandoned his post-election vow to renew the party in opposition -- a U-turn that angered many.
But a copy of the coalition agreement obtained by AFP indicated that he was able to extract major concessions from the conservatives in the final round of talks including control of the powerful finance and foreign ministries, as well as the labour, family affairs, justice and environment remits.
Schulz put a fairer Europe at the heart of his negotiating efforts, insisting that Berlin must join French President Emmanuel Macron's push to deepen eurozone integration.
According to the coalition deal, the parties agreed to support Macron's reform drive and tentatively backed his idea of a eurozone investment budget.
On the hot-button topic of migration, the two camps said they would aim to limit the annual intake to 180,000-220,000 people, a key CSU demand. CSU leader Horst Seehofer is also set to take control of a revamped homeland security ministry.
A recent Insa poll found that support for the CDU/CSU had fallen from 33% to 30.5%, while the SPD slipped from September's historic low of 20.5% to 17%. The AfD meanwhile scored a record 15%.