BERLIN (AP) — Germany’s center-left Social Democrats won the biggest share of the vote in a national election Sunday, narrowly beating outgoing Chancellor Angela Merkel's center-right Union bloc in a closely fought race that will determine who succeeds the long-time leader at the helm of Europe’s biggest economy.

The Social Democrats’ candidate Olaf Scholz, the outgoing vice chancellor and finance minister who pulled his party out of a years-long slump, said the outcome was "a very clear mandate to ensure now that we put together a good, pragmatic government for Germany."

Despite getting its worst-ever result in a federal contest, the Union bloc said it too would reach out to smaller parties to discuss forming a government, while Merkel stays on in a caretaker role until a successor is sworn in.

Election officials said early Monday that a count of all 299 constituencies showed the Social Democrats received 25.9% of the vote, ahead of 24.1% for the Union bloc. No winning party in a German national election had previously taken less than 31% of the vote.

Armin Laschet, the governor of North Rhine-Westphalia state who outmaneuvered a more popular rival to secure the nomination of Merkel’s Union bloc, had struggled to motivate the party’s base and suffered a series of missteps.

"Of course, this is a loss of votes that isn’t pretty," Laschet said of results that looked set to undercut by some measure the Union’s previous worst showing of 31% in 1949. But he added that with Merkel departing after 16 years in power, "no one had an incumbent bonus in this election."

Laschet told supporters that "we will do everything we can to form a government under the Union’s leadership, because Germany now needs a coalition for the future that modernizes our country."

Both Laschet and Scholz will be courting the same two parties: the environmentalist Greens, who were third with 14.8%; and the pro-business Free Democrats, who took 11.5% of the vote.

The Greens traditionally lean toward the Social Democrats and the Free Democrats toward the Union, but neither ruled out going the other way.

The other option was a repeat of the outgoing "grand coalition" of the Union and Social Democrats that has run Germany for 12 of Merkel’s 16 years in power, but there was little obvious appetite for that after years of government squabbling.

"Everyone thinks that ... this ‘grand coalition’ isn’t promising for the future, regardless of who is No. 1 and No. 2," Laschet said. "We need a real new beginning."

The Free Democrats’ leader, Christian Lindner, appeared keen to govern, suggesting that his party and the Greens should make the first move.

GERMANY ELECTIONS: WHO WILL REPLACE ANGELA MERKEL? WHAT YOU NEED TO KNOW

"About 75% of Germans didn’t vote for the next chancellor’s party," Lindner said in a post-election debate with all parties’ leaders on public broadcaster ZDF. "So it might be advisable ... that the Greens and Free Democrats first speak to each other to structure everything that follows."

Baerbock insisted that "the climate crisis ... is the leading issue of the next government, and that is for us the basis for any talks ... even if we aren’t totally satisfied with our result."

While the Greens improved their support from the last election in 2017, they had higher expectations for Sunday’s vote.

The Left Party was projected to win only 4.9% of the vote and risked being kicked out of parliament entirely. The far-right Alternative for Germany — which no one else wants to work with — received 10.3%. This was about 2 percentage points less than in 2017, when it first entered parliament.

Due to Germany’s complicated electoral system, a full breakdown of the result by seats in parliament was still pending.

Merkel, who has won plaudits for steering Germany through several major crises, won’t be an easy leader to follow. Her successor will have to oversee the country’s recovery from the coronavirus pandemic, which Germany so far has weathered relatively well thanks to large rescue programs.

Germany’s leading parties have significant differences when it comes to taxation and tackling climate change.

Foreign policy didn’t feature much in the campaign, although the Greens favor a tougher stance toward China and Russia.

Whichever parties form the next German government, the Free Democrats’ Lindner said it was "good news" that it would have a majority with centrist parties.

MERKEL CANCELS TRIP TO ISRAEL AMID AFGHANISTAN CRISIS, HEIGHTENING FEARS OF INCREASING INSTABILITY IN REGION

"All of those in Europe and beyond who were worried about Germany’s stability can now see: Germany will be stable in any case," he said.

Spanish Prime Minister Pedro Sanchez sent early congratulations to Scholz.

"Spain and Germany will continue to work together for a stronger Europe and for a fair and green recovery that leaves no one behind," he wrote on Twitter.

In two regional elections also held Sunday, the Social Democrats looked set to defend the post of Berlin mayor that they have held for two decades. The party was also on course for a strong win in the northeastern state of Mecklenburg Western-Pomerania.

GET THE FOX NEWS APP

For the first time since 1949, the Danish minority party SSW was set to win a seat in parliament, officials said.