German chancellor Angela Merkel has won a fourth term, but now faces the tricky prospect of forming a coalition with two disparate new partners after voters weakened her conservatives and a nationalist, anti-migrant party surged into parliament.
Ms Merkel's centre-left challenger, Martin Schulz, conceded his Social Democrats had suffered a "crushing election defeat", with projections showing the party's worst performance in post-Second World War Germany.
He vowed to take his party, the junior partner in Ms Merkel's outgoing "grand coalition" of Germany's traditionally dominant parties, into opposition.
"We have a mandate to form a new government, and no government can be formed against us," Ms Merkel told cheering supporters. She added that it wasn't a "matter of course" to finish first after 12 years in power, and that the past four years were "extremely challenging".
Stressing that "we live in stormy times" internationally, she declared: "I have the intention of achieving a stable government in Germany."
The biggest winner was the four-year-old Alternative for Germany (AfD). It finished third after a campaign that centred on shrill criticism of Ms Merkel and her decision in 2015 to allow large numbers of migrants into Germany, but also harnessed wider discontent with established politicians.
One of AfD's leaders, Alice Weidel, said it will provide "constructive opposition". But co-leader Alexander Gauland struck a harsher tone, vowing that "we will take our country back" and promising to "chase" Ms Merkel.
Final results showed Ms Merkel's Christian Democratic Union and their Bavaria-only allies, the Christian Social Union, winning 33% of the vote - down from 41.5% four years ago.
Mr Schulz's Social Democrats were trailing far behind, with 20.5% support, down from 25.7% in 2013 and undercutting their previous post-war low of 23% eight years ago.
AfD won 12.6% of the vote. It was followed by the election's other big winner - the pro-business Free Democratic Party, which returned to parliament after a four-year break with 10.7%.
The Left Party took 9.2% of the vote, coming slightly ahead of the traditionally left-leaning Greens who won 8.9%, completing a parliament that now has six caucuses rather than the previous four.
Thousands took to the streets to protest outside its headquarters in Berlin and in other cities across Germany last night.
People protesting the AfD in Berlin chanting "Say it loud, say it clear, refugees are welcome here." pic.twitter.com/e0hDGMHu4P— kassy (@kassy) September 24, 2017
All mainstream parties have ruled out working with AfD and Ms Merkel's conservatives will not form a coalition with the Left Party. That means two politically plausible governments are mathematically feasible: continuing the "grand coalition" or a combination of Ms Merkel's Union bloc, the Free Democrats and Greens.
That alliance is known as a "Jamaica" coalition because the parties' colours match those of the Caribbean nation's flag.
The Social Democrats were adamant on Sunday night that they would no't continue to serve under Ms Merkel. "It is completely clear that the role the voters have given us is as the opposition," Mr Schulz said.
Referring to AfD's third-place finish, he said "there cannot be a far-right party leading the opposition in Germany".
Reiner Haseloff, the conservative governor of eastern Saxony-Anhalt state, said it would be wrong to ignore AfD's strong result.
"We need an answer - there must be no democratic alternative to our right," he added. "As long as it is there, we haven't completely done our homework."
Anti AfD protest outside its post election party pic.twitter.com/dmqqYgQYAA— James Rothwell (@JamesERothwell) September 24, 2017
AfD is the first party to the right of the conservatives to enter parliament in 60 years. Hundreds of demonstrators descended upon the club where the nationalist party's leaders were celebrating their third-place finish. Several protesters threw bottles as police kept them away from the building in Berlin.