New Zealand’s political opposition was jolted by an abrupt change at the top on Tuesday as the Labour Party leader quit amid dismal polling numbers and a rising star, Jacinda Ardern, took over just weeks before a general election.

Ms. Ardern, 37, has been seen as leadership material since she became Parliament’s youngest sitting member at age 28. But with the New Zealand election campaign already in full swing, and the face of her predecessor, Andrew Little, still on the billboards, Ms. Ardern joked to reporters Tuesday morning that she had just accepted “the worst job in politics.”

Mr. Little nominated Ms. Ardern, previously his deputy, to replace him after two polls this week showed support for the left-leaning Labour Party hitting just 24 percent, its lowest level in decades.

Ms. Ardern said she would run a “relentlessly optimistic” campaign, despite the perils of taking over so close to an election, while Labour’s numbers are at rock bottom.