BERLIN — Chancellor Angela Merkel's Christian Democrats posted their worst-ever election results on Sunday, coming in second to their traditional center-left rival for the first time in a decade and a half as parties prepare for what could be weeks of rocky talks to make a government.

With all 299 districts reporting, the center-right conservatives that have dominated Germany's postwar leadership had just 24 percent of the vote, according to preliminary numbers. That's the lowest mark for the storied party since its founding in 1945.

The center-left Social Democrats, who ran a steady campaign under Olaf Scholz, won 26 percent, a turnaround for the party that started election season in a distant third. It will give him the strongest mandate to form a majority government, but whether he can remains unclear.

And with the results so close, Christian Democratic leader Armin Laschet indicated that he would be doing "everything possible" to make a ruling coalition himself.

The election results will shape the future of policy not only in Berlin, but across Europe, where Merkel's veteran hand will be absent as she moves into retirement. But with no easy path to a ruling majority for anyone, both lead candidates pointed to a lengthy road of talks ahead, saying they hoped to have a coalition agreement in place before Christmas.

The wrangling will take place amid a challenging backdrop for Germany and the European Union, including questions of how to steer the bloc's finances after the coronavirus pandemic and coordinate the continent's stance toward Russia and China.

A coalition is likely to include Germany’s Greens — who came in with a record 15 percent, according to the partial results — and the party will leverage what it can on its core issue of climate in negotiations.

Supporters of the Social Democrats celebrated their rise after Merkel’s 16-year hold on leadership.

At the Social Democrats’ headquarters in Berlin on Sunday, the crowd cheered as a second initial exit poll showed the party narrowly ahead. Taking to the stage, Scholz said the party would wait for the final result, “and then we will get to work.”

“This will be a long election night,” he said. “But what’s also clear is that a lot of voters cast their ballots for the Social Democrats because they want a change in government, and also because they want the next chancellor to be called Olaf Scholz.”

Still, there was no clear path to the chancellor’s office for either man.

Depending on the coalition-building, it could be Laschet, 60, who has overseen a campaign marked by blunders but also one that had gained momentum in recent weeks.

Or it could be Scholz, the 63-year-old finance minister in the current coalition government, who has tried to present himself as the continuity candidate.

“It’s a historic collapse,” Thorsten Faas, a political scientist with the Free University Berlin, said of the conservative bloc’s showing. “A very long evening — and likely very long weeks — are ahead of us,” he said, referring to the close count and likelihood of extended coalition negotiations.

A number of high-profile Christian Democrats failed to win the direct mandate in their seats, according to partial preliminary results. Defense Minister Annegret Kramp-Karrenbauer, who Merkel tried to anoint as her successor, lost her district of Saarbrücken. So did Julia Klöckner, a fellow minister.

Merkel’s home seat on the Baltic coast, which has voted for her in all eight elections in the past 31 years, also switched to the Social Democrats.

Under Germany’s particularly complicated voting system, the losers of the direct vote can still make it into parliament if they are high enough on party lists, but the losses will sting for the party nonetheless.

Scholz’s party has seen a change in its fortunes, after it came in 12 percentage points behind the Christian Democrats in the election four years ago.

“The joy is enormous,” said Malu Dreyer, a former deputy chairwoman of the party and minister-president of the Rhineland-Palatinate state. “We have really caught up over the last few weeks. The SPD is back and we’re a people’s party. There’s no doubt about that.”

She expressed confidence that the party’s small lead will hold and it can start coalition outreach.

“All I can say today is: You don’t become chancellor by being loudest, but by having good results, by speaking to your colleagues and by finding good solutions,” she said.

The exit polls pointed to two coalition options — nicknamed for various color combinations — that are politically palatable to Laschet or Scholz.

One is the “traffic light” coalition between the Social Democrats (red), the Greens and the business-friendly Free Democrats (yellow). The other is the “Jamaica” alliance named after the Caribbean country’s flag: led by the Christian Democrats (black) and including the Greens and the Free Democrats.

The Greens have made clear that they prefer to work with Scholz’s party. The Free Democrats lean toward Laschet’s. That makes either option hard to broker.

Peter Neumann, recently brought on as part of Laschet’s “team of the future” to bolster a flagging campaign, said that talks could realistically stretch until Christmas, a prediction that was echoed by the lead candidates in a television interview.

“It’s a good chance that Angela Merkel gives the next new year speech,” he said, referring to the chancellor’s annual address to the nation.

He said there is nothing to stop the Christian Democrats from trying to form a government, even if they come in second. “It’s not about who the strongest party is, but who can mobilize the majority,” he said.

The campaign was “pretty bad for a long time,” but it had picked up in recent weeks, he said. Merkel joined the campaign, and her party emphasized that a potential Social Democrat coalition could include the far-left Die Linke, hated by much of German society for its ties to East Germany’s former ruling party. Die Linke ended up only just scraping into parliament.

One of the most damaging moments for Laschet came during Germany’s summer floods, when he was caught laughing on camera during an event to remember victims.

Ursula Münch, director of the Academy for Political Education in Tutzing, said the Christian Democrats and their sister party had taken for granted the new voters Merkel had won over during her long tenure, including older women.

“That’s a trust one has to earn, and that’s something the CDU didn’t consider sufficiently,” she said.

The far-right Alternative for Germany party received 10 percent of the vote, dropping three points from two years ago.

The Greens will share kingmaker status with the liberal Free Democrats, on 12 percent.

Cheers echoed through the Columbiahalle near Berlin’s historic Tempelhof airfield, as exit polls flashed over the screens at the Green Party’s election night venue. But the party’s candidate for chancellor, 40-year-old Annalena Baerbock, expressed some disappointment.

“We wanted more, and we failed to achieve that because of mistakes made at the beginning of the campaign,” Baerbock said. “Mistakes made by me.”

Several blunders derailed Baerbock’s early surge in the polls: a failure to declare expenses in time, embellishments on her résumé and accusations of plagiarism in her book.

But when Baerbock strode onto the stage, the crowd was in a forgiving mood. Her speech was interrupted by loud cheers and waves of clapping.

“We have a mandate for the future,” Baerbock said, ending on an upbeat note.