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". They signalled that a stronger alliance with France in the EU would be a priority.
Both stressed the need to ensure Germany's "social cohesion".
It was 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.
Mrs Merkel admitted there had been difficult "blockages" during the Berlin talks. Mr Schulz said they had been "tense and turbulent" at times, and "we argued very intensively".
The talks also focused on tax changes. The CDU is pushing to scrap the solidarity tax paid for developing former communist east Germany.
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.