German politicians have achieved a breakthrough in talks aimed at forming a new coalition government.
A blueprint for formal negotiations was agreed between Chancellor Angela Merkel's Christian Democrats (CDU) and their former coalition partners, the Social Democrats (SPD).
Politicians stayed up all night to discuss the 28-page document, with the talks lasting more than 24 hours.
But they managed to reach agreement on key sticking points such as migration.
They plan to limit asylum-seeker arrivals to about 200,000 annually. The blueprint also speaks of capping at 1,000 a month the number of migrants who will be allowed to join their family living in Germany.
Stress on 'social cohesion'
Mrs Merkel and SPD leader Martin Schulz told a news conference they were optimistic that a new "grand coalition" could be formed.
They spoke of a "fresh start" for Germany, and Mr Schulz said that in Europe "we are determined to deploy Germany's strength".
Both stressed the need to ensure Germany's "social cohesion", a veiled recognition of voter frustration with centrist politics, amid tensions over the influx of asylum seekers.
The September election saw the far-right Alternative for Germany (AfD) win 94 seats in parliament - a first for post-war Germany.
Both the CDU and SPD suffered their worst election results for more than 50 years.
By Jenny Hill in Berlin
After a gruelling all-night session - fuelled by currywurst - Angela Merkel appears to have clinched the deal.
The breakthrough is no doubt a relief to the chancellor, who might have faced the prospect of fresh elections had the talks failed. But Mrs Merkel won't be cracking open the Sekt straight away.
These were just exploratory talks, aimed at establishing whether there's a basis upon which a coalition can be formally negotiated. Before the next round of talks can go ahead, the SPD must give the go-ahead at a special party conference.
Bear in mind that many in the SPD - which had originally refused to work with Mrs Merkel again - blame her for their disastrous election result, and are still uncomfortable about another four years in her shadow.
Even if they approve the negotiations, any coalition treaty will be put to the SPD's 400,000 members in a postal ballot. Mrs Merkel is not out of the woods yet.
German official figures show that 280,000 asylum seekers arrived in 2016, a drop of more than 600,000 on the total for 2015. Arrivals fell after EU countries and Turkey tightened border controls.
However, the number of asylum applications continued to rise in 2016. The huge 2015 influx - many of them Syrians, Iraqis and Afghans fleeing war - created a major integration problem for German authorities.
The centre-right CDU and its Bavarian CSU ally have been unable to form a government since the inconclusive election.
The German daily Die Zeit published the text of the CDU/CSU-SPD blueprint for formal negotiations. Under a coalition the parties would seek to:
- Crack down on tax avoidance in the EU, plugging tax loopholes exploited by US tech giants and other big corporations
- Press for "equal pay for equal work" across the EU, to make the labour market fairer
- Turn the European Stability Mechanism (ESM) - the main bailout fund - into a European Monetary Fund under parliamentary control
- Seek joint policies with France on all major international issues
- Create a centre for artificial intelligence with France
- Adopt measures to reduce child poverty, strengthen equal rights for women and attract more foreign skilled workers to Germany
- Promote renewable energy, so that it achieves a 65% share of power generation by 2030.
Initially the SPD ruled out governing with Mrs Merkel in charge again. But Mr Schulz changed his mind after CDU coalition talks with the liberal Free Democrats (FDP) and Greens broke down.
It is Germany's longest ever post-war period of coalition-building and there is still a long way to go before a coalition deal can be clinched.
The SPD will hold a special congress in Bonn on 21 January to decide how to proceed.