German Chancellor Angela Merkel is set to form her fourth government after the opposition Social Democrats (SPD) voted in favour of another grand coalition.

The vote by 464,000 rank-and-file members ends five months of political deadlock since September's election.

The SPD had been split between the party's leadership, which backed joining the coalition, and its radical youth wing, which did not.

Mrs Merkel, who has been in power for 12 years, congratulated the SPD.

On her party's Twitter feed. she said she "looks forward to working together again for the benefit of our country".

SPD voters approved continuing the coalition with 66% in favour. The party leadership had been concerned younger voters might veto a deal. Vote counting went on through the night at the party headquarters in Berlin.

Interim SPD leader Olaf Scholz declared: "Now we have clarity. The SPD will enter the next government".

The chancellor now faces a range of challenges, including strong opposition from the nationalist Alternative for Germany (AfD).

The anti-immigrant party entered the federal parliament for the first time in September with just over 12% of the vote and now makes up the largest opposition group.

The SPD suffered its worst ever election result and many blamed their coalition with Mrs Merkel's Christian Democrats (CDU/CSU) for that poor performance.

Mrs Merkel, who also did badly, losing 65 seats, had tried and failed to form an alliance with the liberal Free Democrats (FDP) and the Greens.

She was forced to pay a higher price for continuing the existing coalition - the new finance minister will be a Social Democrat.

The SPD will now decide who will fill the six ministerial roles it is entitled to before Mrs Merkel's expected election by parliament on 14 March.

Martin Schulz, the former high-profile SPD chairman, had put himself forward as a possible foreign minister, but dropped the plan amid internal party squabbles over who should fill the post.

He had also annoyed many party members by first ruling out a coalition in the aftermath of the SPD's poor election showing only to enter talks later.