German Chancellor Angela Merkel won a fourth term in office on Sunday but Europe's most powerful leader will have to govern with a far less stable coalition in a fractured parliament after her conservatives hemorrhaged support to a surging far right.

Two years after Merkel left German borders open to more than 1 million migrants, the anti-immigration Alternative for Germany (AfD) stunned the establishment by becoming the first far-right party to enter parliament in more than half a century.

The AfD won 13.0 percent of the vote — more than expected and one of many shocks on a night of drama that saw Merkel's conservatives get their worst result since 1949, and her main Social Democrat (SPD) rivals their worst since 1933.

Describing the far right's success as a test for Germans, Merkel insisted she had a mandate to govern — a formidable challenge as she has little choice but to cobble together a three-way coalition with a pro-business group and the Greens.

'We are the strongest party'

"Of course we had hoped for a slightly better result," a humbled Merkel said after her conservative bloc slumped to 32.9 per cent of the vote — down from 41.5 per cent at the last election in 2013.

But she added: "We are the strongest party, we have the mandate to build the next government — and there cannot be a coalition government built against us."

GERMANY-ELECTION/MERKEL

German Chancellor Angela Merkel casts her vote in Berlin on Sunday. Merkel she now faces an unstable situation as she must now form a coalition, an arduous process that could take months. (Fabrizio Bensch/Reuters)

The euro slipped around 0.4 per cent in early Asian trading as it became clear the results would make forming a coalition tricky for Merkel.

Coalition building could take months as Merkel's only straightforward path to a majority in parliament would be a three-way tie-up with the liberal Free Democrats (FDP) and the Greens — an arrangement untested at national level.

End of 'grand coalition'

The Social Democrats, who have served with Merkel's conservatives as junior partners in a "grand coalition" for the past four years, won just 20.6 per cent of the vote, as nearly half of voters repudiated the two parties that have dominated Germany since World War Two.

SPD leader Martin Schulz said the party would refuse to rejoin a coalition and instead take up its position as the main opposition. The Social Democrats appear to have been hurt badly by being in government, making it difficult to distinguish themselves from Merkel's conservatives.

97669228

A supporter of the German Social Democrats reacts to initial results in the German election. The party will move into opposition after years as part of a grand coalition. (Ronny Hartmann/Getty Images)

After shock election results last year, from Britain's vote to leave the EU to the election of U.S. President Donald Trump, leaders of Europe's establishment have looked to Merkel to rally the liberal Western order.
 
A pastor's daughter who grew up in Communist East Germany, she has acted as an anchor of stability in Europe and beyond. 

Now, she faces an unstable situation at home as she must form a coalition, an arduous process that could take months.

'Tectonic shift'

Sunday's election, fought against the tense backdrop of surging support for far left and far right parties across Europe, delivered a fractured German parliament with six party groups, up from four previously.

Josef Joffe, publisher-editor of Germany weekly Die Zeit, said the vote marked a "tectonic shift in German politics" and that the three-way coalition Merkel looks likely to try to forge will be "highly unstable".

GERMANY-ELECTION/MERKEL

Refugees from Syria supporting German Chancellor Angela Merkel, are shown at an election rally in Torgau, Germany, earlier this month. The AfD has surged as an anti-immigrant group in the wake of Merkel's 2015 decision to leave German borders open to over 1 million migrants. (Reinhard Krause/Reuters)

Leading AfD candidate Alexander Gauland vowed his party would "hunt" the new government, whatever its make-up, adding: "We'll get our country and our people back."

In France, far-right leader Marine Le Pen congratulated the AfD, tweeting: "Bravo to our AfD allies for this historic showing!"

AfD denies racism

A large group of protesters gathered outside the AfD's post-election party and police said they made several arrests.

The European Jewish Congress expressed alarm at the AfD's success, adding: "We trust that centrist parties in the Bundestag will ensure that the AfD has no representation in the coming governing coalition."

Germany Election

Guests at an AfD, election party react to the first projections for the German election in Erfurt. The other parties elected to the Bundestag all refuse to work with the AfD. (Martin Schutt/dpa via AP)

The AfD says immigration threatens German culture, but denies that it is racist: "We will neither tolerate xenophobia nor racist positions. But we simply don't have them either," AfD co-leader Joerg Meuthen said.

The result makes kingmakers of both the FDP and the Greens, both of which have played the role in the recent past but neither of which now has enough support on its own to give Merkel a majority.

'Jamaica' coalition

FDP leader Christian Lindner, an ambitious 38-year-old who preaches an ultra-hard line on Europe and has unsettled the German political establishment, said he was open to coalition talks with Merkel but that Germany needed a change of course.
 
The Greens' Katrin Goering-Eckardt said: "We will see if there can be co-operation."

GERMANY-ELECTION/REACTION MERKEL

People at the Christian Democratic Union CDU headquarters react to the first exit polls in the German general election. Merkel is Europe's longest serving leader. (Kai Pfaffenbach/Reuters)

A three-way tie-up of Merkel's conservatives, the FDP and the Greens — known as a "Jamaica" coalition because the black, yellow and green colours of the three parties match the Jamaican flag — is widely seen as inherently unstable.

The Greens — keen on regulation — and the business-friendly FDP are at opposite ends of the political spectrum and a clash of policy visions would be likely on tax, energy, the European Union and migrants.

Despite losing support, Merkel, Europe's longest serving leader, will join the late Helmut Kohl, her mentor who reunified Germany, and Konrad Adenauer, who led Germany's rebirth after World War Two, as the only post-war chancellors to win four national elections.

With files from The Associated Press