Jacinda Ardern will be New Zealand's next prime minister and hopes to take the country on a more liberal path after nine years of rule by conservatives.
The outcome of a national election nearly a month ago only became clear on Thursday after the small New Zealand First party decided to back Ms Ardern's liberal Labour Party.
Ms Ardern, 37, will be the nation's youngest leader in more than 150 years. She has been compared to other young, charismatic leaders such as President Emmanuel Macron in France and Prime Minister Justin Trudeau in Canada.
New Zealand First leader Winston Peters said his party's choice was between "a modified status quo" with the incumbent conservatives or an option for change.
The liberal Green Party will support the coalition but will not be a part of the government's policy-setting cabinet. The Green Party still has to ratify the deal but its leader, James Shaw, said he is confident that will happen.
Ms Ardern said she wants to lead a government that looks after the environment and the country's most vulnerable people.
"It is an absolute honour and a privilege," she said.
Outgoing prime minister Bill English, who appeared emotional, said he was disappointed but felt he had left New Zealand in good shape and that the country has plenty of opportunities ahead.
Asked how he rated Ms Ardern, he noted her rapid rise.
"That's a fairly remarkable performance given that just 10 or 12 weeks ago she was the deputy leader of a failing opposition."
New Zealanders have been waiting since the September 23 election to find out who will govern after the voting ended without a clear winner.
New Zealand's currency fell by about 2% as the result became clear.
The policies of New Zealand First are nationalistic and eclectic. Mr Peters wants to drastically reduce immigration and stop foreigners from buying farms. He opposed plans by Mr English's National Party to increase the pension age and plans by Labour to tax certain water users.
New Zealand First is expected to extract policy concessions and win some ministerial posts by joining the Labour coalition. Ms Ardern said the details would be released in the coming days.
Mr Peters said in his announcement that his party's perception of how capitalism needs to change influenced its decision.
"Far too many New Zealanders have come to view today's capitalism not as their friend but as their foe, and they are not all wrong," he said. "That is why we believe that capitalism must regain its responsible, human face."
In his election campaign, Mr English said his party had grown the economy and produced increasing budget surpluses which benefited the nation.
Ms Ardern said she wants to build thousands of affordable homes to combat runaway house prices, spend more on health care and education, and clean up polluted waterways.
Under New Zealand's proportional voting system, larger parties must typically form alliances with smaller parties to govern.
A government needs at least 61 seats to hold a majority in the 120-seat parliament. National won 56 seats, Labour won 46, New Zealand First won nine and the Green Party won eight.