Germany will cap the number of refugees it accepts and restrict their family reunification rights as part of a coalition deal that promises to end the democratic deadlock that followed last September's elections.
The would-be coalition also aims to generate 65 per cent of Germany's energy from renewables by 2030 and will draw up a timetable to phase out coal power completely.
The deal - which would give Angela Merkel her fourth term as chancellor - emerged after five days of talks that ended with an exhausting 24-hour session fuelled by currywurst, a steamed and fried sausage usually served with curry ketchup.
The proposed new restrictions on refugees reflect discontent over the country's generous attitude to asylum seekers, which has led to a surge in support for the far-right anti-immigrant Alternative for Germany (AfD).
Since the election, AfD's polling numbers have continued to rise, while those of the would-be coalition partners - Merkel's centre-right CDU and Martin Shulz's centre-left SPD - fell to new lows.
A CDU-SPD coaltion, together with the CDU's Bavarian counterpart the CSU, was the only practical option for majority government, after a failed attempt by Merkel to bring the Greens on board with the pro-business FDP.
The party leaders agreed to a 28-page deal on Friday morning. It must now be voted on by the SPD party conference later this month, where there is likely to be resistance from members who believe a coalition would further damage their electoral appeal.
On some polling, around half of SPD supporters oppose a new grand coalition.
If the deal jumps that hurdle, official coalition talks will begin in February and a government is likely to be formed in late March if the formal coalition treaty is approved by another SPD member ballot.
Otherwise, new elections are all but inevitable.
Europe has been holding its breath over the coalition talks, the longest in post-war German history.
Though most European economies - and the euro - have been in good shape in recent months, the lack of German leadership was threatening to affect Brexit and stall the push for European Union reform, led most vocally by French president Emmanuel Macron.
The euro jumped to a three-year high against the US dollar after the deal was announced, reflecting the relief of analysts and the perceived importance of German leadership to the European economy.
European Commission President Jean-Claude Juncker said he was "very satisfied" with the content of the deal.
Merkel said the deal showed the two parties could work together and in "10 to 15 years we will still be able to live well in Germany".
"We are convinced that Europe needs a fresh start and have developed the right ideas to go with it."
She said the talks had been "intensive, serious (and) very deep".
But she warned the coming coalition negotiations "probably won't be easier than the exploratory talks."
Under the deal, the number of refugees with "limited protection status" who could bring their families to join them would be limited to 1000 per month, and the number of asylum seekers taken in altogether would be limited to 180,000 to 220,000 per year.
The deal also included an ambitious program to build 1.5 million new apartments, to ban the use of glyphosate pesticides, and to reduce the ???solidarity tax' that was created to help the East catch up with the West after reunification.
There were also compromises on tax and employer-funded health insurance, and a plan to push for greater financial EU integration.