Germany's centre-left Social Democrats (SPD) have reached an agreement on a coalition government with Chancellor Angela Merkel's conservatives (CDU/CSU).
A deal on the division of the key ministries was seen as the last major hurdle towards forming a coalition.
The agreement looks set to end more than four months of wrangling since inconclusive elections in September.
Negotiators have been in non-stop talks since Tuesday morning.
After Germany's longest post-war period of coalition-building, there are now hopes a government could be in place by Easter.
The SPD looks set to control six ministries, including finance and foreign affairs.
German media say party leader Martin Schulz, a former president of the European Parliament, is hoping to get the job of foreign minister.
But the whole agreement still needs the approval of the SPD's 460,000 members, who will have the final say in a postal vote due in the coming weeks.
Those opposed to any deal with Mrs Merkel include a new group within the SPD calling itself NoGroKo (no grand coalition).
Mr Schulz at first ruled out going back into government with Mrs Merkel's centre-right CDU and its Bavarian sister party, the CSU.
The parties had seen their popularity drop after being in coalition on and off since 2005.
Martin Schutz is the former president of the European Parliament and leader of the SPD party
But he changed his mind when CDU/CSU coalition talks with the liberal Free Democrats (FDP) and Greens broke down.
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.
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.
By Damien McGuinness, BBC News, Berlin
Handing Germany's centre-left control of finance, foreign and labour policy would have a big impact on the rest of the world, particularly Europe.
A Social Democrat finance ministry - replacing pro-austerity Wolfgang Schäuble - is more likely to go along with French President Macron's ambitious plans for EU reform, by allowing more German support for struggling eurozone economies.
And at home these powerful ministries would help the SPD push for key left-wing policies, such as better rights for employees.
All of this could go down well with SPD party members, who will vote on any final coalition deal.
An agreement which looks like a win for the SPD will increase the likelihood that they will vote yes.
But if they vote no, then the most likely outcome could be fresh elections.
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.
Meanwhile, politicians from the SPD and CDU/CSU have been hailing the agreement.
"I think it's about time we had the prospect of a government in Germany. So it's a good day," said Alexander Dobrindt of the CSU.