Germany's two main political parties look set to form a grand coalition government under Angela Merkel.
The liberal-conservative Christian Democratic Union (CDU) and the centre-left Social Democrats (SPD) negotiated through the night in a marathon final push to nail down an agreement.
Chancellor and CDU leader Angela Merkel has been struggling to put together a government since the general election last September produced an inconclusive result.
CDU and its Bavarian sister party CSU had seen their popularity drop after being in coalition on and off since 2005.
SPD initially vowed to stay in opposition but party leader Martin Schulz changed course and opened negotiations with Mrs Merkel after she failed to clinch a deal with the Greens and the Free Democrats (FDP) in November.
Negotiators have agreed on the division of key ministries - one of the last hurdles towards forming a government. The SPD looks set to control six ministries including finance and foreign affairs.
However, the SPD's 464,000 members will be asked to ratify the deal, and could yet reject it in a postal vote whose result is due to be announced on 2 March.
Many in the party fear that re-entering a coalition with CDU could damage it in the long term.
Other than distributing ministries, there have been big stumbling blocks in the coalition talks over workers' rights and healthcare. Immigration, Europe, and tax, have also been points of contention.
In a joint news conference on Wednesday, Chancellor Merkel said the agreement gave the basis for a "good and stable government".
SPD leader Martin Schulz thanked the conservatives for making what he said were tough compromises.
In a tweet, he said the deal "achieved a lot for people" and he would be recommending that his party members accept it.
Mr Schulz also said he would step down as the SPD's leader in March, reports say. He will be replaced by former Labour and Social Affairs Minister Andrea Nahles.
German media said Mr Schulz, a former president of the European Parliament, is hoping to get the job of foreign minister.
FDP leader Christian Lindner said the CDU had been "willing to give the SPD everything - key ministries and top positions - to keep the chancellorship".
He said in a tweet: "Relaunching the German model in this parliament with this arrangement and this chancellor will clearly not be possible."
Both Mr Schulz and Mrs Merkel have been under pressure to see off a challenge by the far-right Alternative for Germany (AfD), which became the third-biggest party in September's election.
AfD leader Alice Weidel criticised the coalition's proposed immigration policy - which would see up to 220,000 asylum seekers given residency each year - and a scheme to encourage highly-qualified people to move to Germany.
"The chasm between the ruling parties and the people of our country has never been bigger," she told Die Welt newspaper.
European Union allies, such as France, see Germany as a pillar of stability in the bloc and have been hoping Mrs Merkel succeeds.
Top EU officials, including the Economics Commissioner Pierre Moscovici, welcomed the breakthrough on Wednesday.