In New Zealand, political parties must band together to form a coalition government if no party wins enough seats to govern outright. Labour did not win the most seats in the September election; that distinction went to the center-right National Party, led by the incumbent prime minister, Bill English.

But National did not win enough to govern alone, and the decision about who would become prime minister was left to the eccentric, populist leader of a minor party, Winston Peters of New Zealand First.

Weeks of negotiations followed before Mr. Peters threw his weight behind Ms. Ardern on Thursday night. Neither she nor her rival knew Mr. Peters’s decision before he announced it on live television.

Describing herself as “relentlessly optimistic,” Ms. Ardern will now face a National opposition of 56 members clamoring at the gates — smarting from losing an election they believed they had won — and must hold together a three-party governing deal, while also delivering on the change she promised.

The morning after her ascension, at a girls’ high school not far away from Parliament, final-year students were buzzing at the prospect.

Mia Faiumu, 18, and Narjis al-Zaidi, 17, two leaders of the feminist club at the school, Wellington East Girls’ College, hoped Ms. Ardern would improve the national curriculum for sex and consent education as well as decriminalize abortion, as she had promised (abortion is permissible in New Zealand with a doctor’s approval but remains illegal).