German Chancellor Angela Merkel says a coalition deal struck to end four months of limbo will be the basis of a "good and stable government".

An "in principle" deal was agreed on Wednesday between Mrs Merkel's party and two others, setting her on the path to a fourth term.

It involves Mrs Merkel's Christian Democratic Union (CDU), its Bavaria sister party the Christian Social Union (CSU) and the Social Democrats (SPD).

In a news conference on Wednesday afternoon, Mrs Merkel said the deal was the basis of a good and stable government, which "our country needs and which many in the world expect from us".

:: The end of limbo in Germany? Not necessarily


Image: Martin Schulz, leader of the German Social Democrats (SPD), may become foreign minister

She said: "We know that in order to make sure it continues to be good for our people in the future, we will have to modernise infrastructure, address the challenges of digitalisation.

"This was one of the toughest chapters.

"It wasn't easy, focusing on humanity on one hand and on directing and steering immigration on the other, but here too we managed to come up with a good packet of measures."

Martin Schulz, who confirmed he would step down as SPD leader on Wednesday afternoon, said the party had pushed through many of its own policies to the agreement.

He said: "You'll forgive me for thanking Mrs Merkel and Mr Seehofer, especially regarding the European policy chapter of this deal, because what we wrote down in this coalition agreement about the European Union and its future will be a fundamental change of direction in Europe.

"With this coalition agreement, Germany will take an active and leading role in the European Union again."

Image: Coalition talks of CDU, CSU and SPD in Berlin have ended in an agreement

Talks between the parties carried on throughout the night.

Senior EU officials welcomed the announcement, with Pierre Moscovici, the commissioner for economic and financial affairs, tweeting it was "good news for Europe".

Now-former SPD leader Mr Schulz looks set to become foreign minister.

The parties agreed to raise the German contribution to the EU and said they "regret" Brexit.

The announcement added that Berlin wants a "trusting relationship with Britain" after it leaves the bloc.

The deal will help lift uncertainty about Mrs Merkel's future but will be subject to the approval of the 464,000 members of the SPD by a postal ballot.

Image: Peter Altmaier of the Christian Democratic Union (CDU) leaves after the all-night talks

The SPD served as a junior government partner under Mrs Merkel from 2013-17.

According to German public broadcaster ARD, the final disputes centred around "ministry remits and personnel questions".

Days of talks between negotiators had covered everything from foreign policy to labour issues and healthcare. The latest talks lasted 24 hours.

Sources indicate the Social Democrats will get the foreign, labour and finance ministries, a major prize held by Mrs Merkel's Christian Democrats for the last eight years.

Olaf Scholz, the SPD mayor of Hamburg, is set to become finance minister.

The SPD tends to favour spending over austerity, so there could be a move away from the firmer fiscal policies of former ministers.

Image: Coalition talks of CDU, CSU and SPD in Berlin have ended in an agreement

The high-profile jobs may sweeten the deal for the members of the SPD, many of whom are sceptical of the disastrous election results following four years as a junior partner in the coalition.

Should the agreement be rejected by SPD party members, Mrs Merkel will either have to lead a minority government or call a new election.

An attempt to form a coalition with small parties collapsed in November.

The country has been in limbo since the 24 September election, breaking its record for the longest time between an election and the swearing-in of a new government.

Mrs Merkel has been leading a caretaker government since October, which works for day-to-day business but means Germany has not been able to launch major initiatives or play a significant role in the debate on the future of the EU.