German Chancellor Angela Merkel's conservatives and the Social Democrats sealed a deal Wednesday on a new coalition, officials said, potentially ending four months of political standstill 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 often contentious talks.
"And now we all want to take a shower because we negotiated long and hard in these last hours."
Public broadcaster ARD said the final disputes had centred around "ministry remits and personnel questions".
A source close to the talks told AFP the sides had agreed the SPD would take over the finance ministry.
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 pact between her CDU/CSU bloc and the Social Democratic Party must still be approved by the SPD's sceptical rank-and-file .
The agreement for a renewed "grand coalition" comes after days of talks in which negotiators from all three parties haggled over everything from foreign policy to labour issues and healthcare.
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. Media reports said he was now set to take over the foreign ministry.
Merkel's fate now lies in the hands of the SPD, as Schulz has promised to give his party's 460,000 members the final say on whether to accept the coalition pact.
Observers expect the referendum to be tight, with the SPD's left and youth wings fiercely opposed to another four years governing in Merkel's shadow.
The party's fiery youth chief Kevin Kuehnert has led a campaign against another "GroKo", as the grand coalition is known.
The referendum will be held by postal ballot, with the result expected to be announced in early March.
A green light could see a new Merkel-led government in place by the end of next month.
A thumbs-down could spell disaster for Merkel and Schulz, whose political lives hang in the balance, and see the country headed for fresh elections.
With so much at stake, Schulz was determined to extract as many concessions as possible from the tortuous coalition talks to win over sceptics.
While details of the final agreement have yet to be released, former European Parliament chief Schulz has put a fairer Europe at the heart of his efforts, insisting that Berlin must join French President Emmanuel Macron's push to deepen eurozone integration.
In a draft version of the coalition pact seen by AFP, 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.
The SPD however won assurances that family reunifications for refugees would resume in August, restricted to 1,000 people a month.
It was not immediately clear how the final sticking points in the negotiations were resolved, such as the SPD's insistence on limiting short-term contracts and overhauling the two-tier healthcare system.
On defence spending too, both sides remained at odds as the finish line neared with the conservatives more open than the SPD to raising military spending closer to NATO targets, as pushed for by US President Donald Trump.
But the protracted haggling has left its scars, and surveys suggest the two camps could lose their majority in fresh elections in case of a "no" vote from SPD members.
A recent Insa poll found that support for the CDU/CSU had fallen from 33 to 30.5 percent, while the SPD slipped from September's historic low of 20.5 percent to 17 percent.
The AfD meanwhile scored a record 15 percent.