Prime Minister Mette Frederiksen of Denmark said on Thursday that snap parliamentary elections would be held next month. The announcement came just weeks after she surged in public opinion polls for standing up to President Trump’s threats to take over Greenland, a semiautonomous Danish territory.

Ms. Frederiksen, who became prime minister in 2019 after her party, the Social Democrats, struck a deal to form a minority government with other left-leaning parties in Parliament, said the next poll would be held on March 24, more than half a year before her deadline to call such elections.

“As everyone knows, the conflict about Greenland isn’t over yet,” she said in a speech on Thursday to Parliament that amounted to the opening of what is likely to be a quick campaign to keep her job.

Mr. Trump has backed down from his original threat to seize Greenland and ruled out the use of force. Ms. Frederiksen, nonetheless, suggested in her speech that the United States, at least during Mr. Trump’s presidency, could become a threat to Denmark’s security and stability.

“Denmark has to continue rearming itself,” she said, pointing to “the Russian war machine from the east, threats from the west and the risk of terror from the south.”

It’s a test of whether standing up to Mr. Trump could pay political dividends.

Ms. Frederiksen, who has made a name for herself with her refusal to kowtow to Mr. Trump, did not directly name the president in her address. But she made several references to the security threats facing her country.

“We must define our relationship with the United States,” she said.

Greenland’s prime minister, Jens-Frederik Nielsen, has said that Greenlanders would rather stick with Denmark, their former colonizer, than join the United States. The Faroe Islands, the other part of the kingdom, also chose to forgo planned talks last month with Denmark to discuss boosting their autonomy.

“We must secure the future of the Danish kingdom,” Ms. Frederiksen said.

Within hours, the competition intensified. Three other politicians announced their candidacy for prime minister, including Troels Lund Poulsen, the defense minister who is also the leader of Venstre, a center-right party with the second-most seats in Parliament.

In a Facebook announcement, he also pointed to the turmoil of the Greenland crisis and directly framed the United States as a threat to Denmark’s safety and security.

“I believe in Denmark and our Kingdom — we have to defend it,” Mr. Poulsen said in his announcement. “As a country, we are challenged by Putin from east and Trump from west.”

Ms. Frederiksen did not say whether she would resign as prime minister if her party lost the largest number of seats. But experts said that calling the elections now would most likely put her and her party in a strong position.

She had to call elections at any point before November. Before the Greenland crisis, she had been lagging in polls. Late last year, her party lost control of Copenhagen in municipal elections for the first time in more than a century, in part because voters were alarmed by the party’s heavy-handed approach to immigration.

Then, in January, Mr. Trump threatened Greenland. And many thought she handled the crisis well, said Mikkel Runge Olesen, a researcher at the Danish Institute for International Studies in Copenhagen.

“She had to call elections very soon anyway,” he said. “So why not do it now while the Danish population still remembers that she stood up to Donald Trump?”

Jon Rahbek-Clemmensen, the head of strategy and great power competition at the Royal Danish Defense College in Copenhagen, also said she might have a short-lived sweet spot, politically speaking.

“There’s been a rally-around-the-flag effect,” he said.

Calling a vote in the middle of the Greenland crisis could have been seen as opportunistic or irresponsible, he said. But waiting too long could have meant losing her strategic advantage. It was no coincidence, he said, that the prime minister waited until after Mr. Trump’s State of the Union address on Tuesday night. Mr. Trump did not mention Greenland at all.

If he had, Dr. Rahbek-Clemmensen said, “the crisis would have been reactivated and I imagine that they wouldn’t have pressed the button.”