Jacinda Ardern, who became a global liberal icon as New Zealand’s prime minister but faced deepening political challenges with an election looming at home, said in a surprise announcement on Thursday that she would step down as the country’s leader.

In a tearful speech in the New Zealand city of Napier, where Ms. Ardern’s Labour Party was hosting its summer caucus retreat, she said she did not feel personally prepared to complete another term. She will leave office by Feb. 7, she said.

“I believe that leading a country is the most privileged job anyone could ever have, but also one of the more challenging,” Ms. Ardern said. “You cannot and should not do it unless you have a full tank plus a bit in reserve for those unexpected challenges.”

She added: “This has been the most fulfilling five and a half years of my life. I am leaving because with such a privileged job comes a big responsibility.”

Labour lawmakers will elect a new leader of the party — and the country — in three days’ time, Ms. Ardern said.

Ms. Ardern, 42, became prime minister in 2017 and won a historic re-election victory in 2020, largely on the strength of New Zealand’s response to Covid, which allowed residents to live a mostly normal life for much of the pandemic. But her party has since fallen sharply in the polls amid economic troubles and some highly publicized instances of violent crime.

Soon after her unexpected rise to power as New Zealand’s youngest prime minister in 150 years, Ms. Ardern became something of an international celebrity. She had a daughter while in office and brought her to the floor of the United Nations. To admirers, she became the sunny face of progressivism, and a welcome alternative to the politics represented by then-President Donald J. Trump in the United States.

But it was her response in 2019 to the massacre of 51 people at two mosques in Christchurch, by a gunman espousing anti-Muslim, anti-immigrant hatred, that solidified her image as a hero of the global left. “We represent diversity, kindness, compassion. A home for those who share our values. Refuge for those who need it,” she said at the time of New Zealand. Within a week, Ms. Ardern had imposed temporary restrictions on the purchase of guns, followed by the passing of a law a few weeks later that banned most semiautomatic weapons.

Ms. Ardern said she had informed party members earlier Thursday of her decision to resign. She said she would remain a member of Parliament for her electorate in the city of Auckland until April, in order to avoid the need for a by-election.

Labour has been facing major political challenges ahead of the Oct. 14 election. For almost a year, the party has polled behind the center-right National Party, led by Christopher Luxon, a former aviation executive. As of December, support for Labour was at 33 percent, compared with 38 percent for the National Party.

Still, Ms. Ardern has remained personally popular with the electorate. She has regularly outperformed Mr. Luxon in polls as most New Zealanders’ “preferred prime minister.”

Mr. Luxon said last month that the polls showed New Zealanders felt the country was going in the “wrong direction.” He added: “What they can see is a government that’s just not getting things done.”

Voters are principally concerned about the many economic issues the country faces. Home prices in New Zealand, which surged over the past decade, fell 12 percent in 2022. Borrowers, most of whom are able to fix their mortgage rate for only a few years at a time, are at high risk of negative equity, as they balance a high cost of living and surging inflation with the twin catastrophes of falling home prices and rising interest rates.

A perceived rise in violent crime, including high-profile incidents in which employees of corner stores have been attacked and in one case killed, has also contributed to a sense of dissatisfaction.

Ben Thomas, a political commentator and former press secretary for the National Party, said Ms. Ardern’s resignation would come as a surprise for many New Zealanders and could spell disaster for Labour.

“She’s Labour’s number one political asset,” he said. “It would very much be a personal decision to step down, as opposed to a considered strategy about what would be best for Labour in the election.”

In her remarks, Ms. Ardern addressed her partner, the television presenter Clarke Gayford, and their 5-year-old daughter Neve. They were, she said, “the ones that have sacrificed the most out of all of us.”

“To Neve: Mum is looking forward to being there when you start school this year,” she said. “And to Clarke — let’s finally get married.”

In resigning almost a year before a general election, Ms. Ardern follows closely in the footsteps of a recent predecessor, John Key, who stepped down in 2016, allowing his deputy, Bill English, to take his place as leader of the National Party and prime minister.

But there is no obvious successor to Ms. Ardern. Grant Robertson, Labour’s deputy leader, will not seek the leadership, Ms. Ardern said. Any candidate seeking to lead Labour must have the support of at least two-thirds of its lawmakers, a requirement that raises the prospect of a power vacuum, prolonged infighting and a relative newcomer, at least in voters’ eyes, leading the party and the country.

Livia Albeck-Ripka contributed reporting.