COPENHAGEN, Denmark (AP) — Prime Minister Mette Frederiksen was in a strong position to remain in power after her Social Democrats won the most votes Tuesday in Denmark’s election and a center-left bloc in Parliament that backs her appeared set to retain a majority by just one seat.

The result was preliminary and based on the assumption that a vote count in Greenland expected early Wednesday would give the autonomous Danish territory’s two seats to the center-left bloc.

“I am so thrilled and proud. We have gotten the best election result in 20 years,” Frederiksen told supporters early Wednesday in Copenhagen.

Despite the success, Frederiksen, who heads a Social Democratic minority government, said she would resign as prime minister and try to form a new government with broader support across the political divide, something she had said suggested before the election.

“It is also clear there is no longer a majority behind the government in its current form. Therefore, tomorrow I will submit the government’s resignation to the queen,” said Frederiksen, adding that she would meet with other parties about forming a new government.

Frederiksen was forced to call the vote earlier this month amid the fallout from her government’s contentious decision to cull millions of minks as a pandemic response measure. The cull and chilling images of mass graves of minks have haunted Frederiksen since 2020 and eventually led to cracks in the center-left bloc.

The Social Democrats remained Denmark’s top party with 28% of the vote, but it remained unclear long into the night whether the center-left parties together would reach the 90 seats needed for a majority in the 179-seat Parliament. Exit polls suggested they would fall short, but the decisive seat flipped at the very end of the vote count.

Before that former Prime Minister Lars Løkke Rasmussen appeared set to become kingmaker. His newly formed centrist party won 9% of the vote for 16 seats, according to the preliminary results.

Løkke Rasmussen said he too wanted to Mette Frederiksen to try to form a government but he would not point at her “as prime minister.”

A two-time government leader who lost the 2019 election to Frederiksen and abandoned the center-right Liberal party following an internal power struggle, Løkke Rasmussen, wouldn’t say whom he would back as the next prime minister or whether he saw that role for himself.

“I know for sure that Denmark needs a new government, “ he told jubilant supporters in Copenhagen. “Who is going to sit at the end of the table we do not know.”

Denmark may be a small, tranquil country known for having some of the happiest people on Earth, but its politics is filled with intrigue that will be familiar to fans of the fictional Danish TV drama series “Borgen.”

Before the election, Frederiksen, 44, floated the idea of a broader alliance that would also include opposition parties, but was rebuffed by opposition leaders Jakob Ellemann-Jensen of the Liberals and Søren Pape Poulsen of the Conservatives, who both ran as candidates for prime minister in a center-right government.

Even though the election result suggested she could ostensibly carry on as prime minster with only center-left support, Frederiksen said she would keep her ambition to also reach out to opposition parties.

“The Social Democrats went to the election to form a broad government,” she said. “I will investigate whether it can be done.”

Denmark’s more than 4 million voters could choose among over 1,000 candidates — the most ever — from 14 parties. Four of the 179 seats in the Danish legislature, Folketinget, are reserved for the Faeroe Islands and Greenland, which are autonomous Danish territories.

Concerns about rising inflation and energy prices linked to Russia’s war in Ukraine and a shortage of nurses in the public health care system were key themes in election campaigns.

“What I feel is important and is a worry to many are the soaring prices, whether it be electricity, bread or gasoline,” said Inge Bjerre Hansen, 82, after casting her vote in Copenhagen. “My son is reducing the number of his visits because it has become expensive to fill the tank (of his car).”

Unlike in previous elections, immigration received little attention. Denmark has some of Europe’s strictest immigration laws and there is broad agreement among the major parties to keep it that way.

That and internal squabbles help explain the collapse of the populist Danish People’s Party, which spearheaded Denmark’s crackdown on immigration two decades ago. Once polling over 20%, the party recorded its worst parliamentary election result since its creation in 1995, with around 3% of the vote, the results showed.

The Danish People’s Party faced competition for nationalist voters from new right-wing parties. Among them are the Denmark Democrats, created in June by former hardline immigration minister Inger Støjberg. In 2021, Støjberg was convicted by the rarely used Impeachment Court for a 2016 order to separate asylum-seeking couples if one of the partners was a minor.

She was eligible to run for office again after serving her 60-day sentence. The official results showed her party getting 8%.

Frederiksen, who became Denmark’s youngest prime minister when she took office at 41 more than three years ago, teamed up with the opposition to hike NATO-member Denmark’s defense spending in the wake of Russia’s invasion of Ukraine. Her steadfast leadership during the COVID-19 pandemic was partly overshadowed by the mink-culling episode.

The decision to slaughter up to 17 million minks to protect humans from a mutation of the coronavirus was taken in haste and without the required legislation in place. It dealt a devastating blow to Danish mink farmers, even though there was no evidence the mutated virus found among some minks was more dangerous than other strains.

___

Ritter reported from Stockholm. Associated Press journalists and Aleksandar Furtula and Anders Kongshaug in Copenhagen contributed to this report.