Andrew Little has been elected the Labour Party's leader and has the task of rebuilding the party after its disastrous election loss in September.
The Engineering, Printing and Manufacturing Union's former national secretary won the leadership by a narrow margin from Wellington Central MP Grant Robertson.
In the end, it was substantial support from Labour's affiliated unions which gave Mr Little the votes he needed to win the leadership.
Under Labour's preferential voting system, the votes of MPs are worth 40 percent of the total, party members 40 percent and the union affiliates 20 percent.
Once first preferences were counted, Mr Robertson was ahead on 36.58 percent, while Mr Little was on 29.36 percent. The lowest-polling candidate, Nanaia Mahuta, then dropped out and her second preference votes were distributed among Mr Robertson, Mr Little and the fourth candidate, David Parker.
All of Ms Mahuta's second preferences among the MPs who voted for her went to Mr Little. He also strengthened his support among party members and the unions to take the overall lead but still fell short of a 50 percent plus one majority.
Mr Parker then fell out of the contest and his second preferences were counted.
Mr Little's union support pushed up to 75.56 percent, while Mr Robertson could garner only 24.44 percent of the union votes.
That gave Mr Little enough support to get a majority and claim the leadership. However, Mr Robertson comfortably won more votes among MPs and party members.
Mr Little's reliance on the union vote and the fact the overall vote was so close has raised questions about whether Labour will unite behind him as leader.
But at a news conference to announce his win, Mr Little was emphatic he had won the vote and that the caucus would be united and disciplined. He said he would spend the next few days talking to fellow MPs before determining what roles they would have.
Mr Little thanked the other leadership contenders and said there was a clear place for all three to hold senior leadership roles in the party. As well, he would start the process of reviewing the party's policies and repeated his belief that the capital gains tax policy and the proposal to lift the eligibility age for New Zealand Superannuation should be dropped.
He said Labour had to start talking about the issues which mattered to people. That was mainly about their jobs and incomes, and how they could get a job if they did not have one.
Mr Little reserved special criticism for Prime Minister John Key, saying while Mr Key portrayed the image of a good guy but was responsible for vile and nasty politics.
Mr Key, in turn, offered his congratulations and said he intended to take Mr Little seriously.
"My personal view is that Labour have the wrong policies and are a very divided party, so I think he's in for a very tough job," he said.
"But on an individual level, I offer him my congratulations."
Meanwhile, Mr Robertson, who narrowly lost the contest, said he would never stand for the Labour leadership again and conceded he was disappointed not to win.
"Having now put myself forward for the Labour Party leadership twice, I can assure you I will not be doing it again," he said.
"There will be no requirement for a leadership contest for some time to come because I am sure that Andrew will be the leader and the prime minister for many years.
"But I can make a total commitment that I will not be putting my name forward again."
Mr Parker said he would not seek to be finance spokesperson or deputy leader. He said he had made that clear at the beginning of the leadership campaign and had nothing to do with Mr Little.
Ms Mahuta refused to say whether she wanted to be deputy leader.
The new Labour leader now has a busy few days ahead as he reorganises the caucus and has a deputy elected before Parliament resumes sitting next week for its last session before Christmas.
How events unfolded - LIVE BLOG, with Craig McCulloch, Political Reporter
NOW the press conference is over.
MPs leaving the room. One David Cunliffe is heard asking, "Backbencher?" - a reference to the pub across the road.
Mahuta says it's for Little to decide who the deputy is. Won't say whether she wants it "out of respect for Andrew."
David Parker says he made it clear at the beginning of the process to caucus that he would not be putting himself forward as deputy or finance spokesperson.
However he says he has no plan to leave politics before the end of this term.
Grant Robertson says he'll have a chat with the party about the math, given how close it was, but says there's very little room for error.
Grant Robertson says he's put his name forward twice and he's now taking the idea of him running off the table.
Nanaia says she's pleased with the result.
Grant says he's disappointed, but thinks Andrew Little will be an excellent and strong leader.
He says Mr Little has his full support and he will not run for leader again under any circumstance.
Congratulations @AndrewLittleMP.— Laila Harré (@lailaharre) November 18, 2014
Nope. Conference still going.
David Parker gives commiserations to Grant Robertson.
"That's a very close result. I got slammed. So did Nanaia."
He pledges full support to Andrew Little.
Press conference over. MPs applaud.
Little says he needs every single one of the caucus working hard and in a focussed way to win in 2017. Doesn't agree that there's "dead wood" in the party.
Mr Little says, as leader, he will indicate which parties he could work with in a Government, and what policies of potential partners Labour finds acceptable.
Mr Little says he's confident Grant Robertson will give him the full three years.
Grant Robertson says he will not have another tilt at the leadership.— Chris Bramwell (@rnzgallerychris) November 18, 2014
Mr Little asked about "talk" that Carmel Sepuloni might be his deputy. He responded that he "hasn't heard that talk." Sepuloni, standing behind him, laughs.
Mr Little says he wants all four of his contenders to hold senior roles in the party.
Mr Little says he'll have discussions with all caucus members over the coming days about their roles in the party.
He won't reveal his preference for a deputy leader.
More Labour MPs had confidence in Nanaia Mahuta to be leader than Andrew Little. Think abut that.— David Farrar (@dpfdpf) November 18, 2014
Mr Little says the caucus will back him. "All parts of the party voted and I won that vote"
Answering questions, Mr Little says New Zealanders are looking for Labour to go back to basics and what matters to them.
Andrew Little arrives to the caucus room to applause from gathered MPs.
He thanked his fellow contenders, calling the contest a "clean fought race".
Mr Little promised to deliver a plan, discipline and focus to Labour.
"The most important task is to reach out to voters... we need to develop a strategy and a policy and priorities that are relevant to them" he said.
New Labour leader Andrew Little comes out to address supporters
Andrew Little is the new leader of the Labour Party.
He's beaten Grant Robertson, David Parker, and Nanaia Mahuta, for the top job, after a month long leadership battle.
Labour MPs' votes counted for 40 per cent of the final result; the party members were also worth 40 per cent, and the affiliated unions 20 per cent.
Mr Little is about to give his first speech (2pm) in the role to the Labour caucus and reporters.
The contest was triggered by the resignation of David Cunliffe a week after the general election, in which Labour's share of the vote fell to an historic low of just over 25 percent.
The least preferred candidate in Caucus gets to lead. This will end well.— Philip Matthews (@secondzeit) November 18, 2014
surprise surprise, being a former union boss really counts for something in a Labour leadership election. well done, @AndrewLittleMP!— Di W (@di_f_w) November 18, 2014
BREAKING NEWS - Andrew Little wins Labour leadership race
The countdown is on: just 25 minutes until the new leader of the Labour Party is revealed.
It's a four-way face-off, featuring Grant Robertson, Nanaia Mahuta, Andrew Little and David Parker.
The victor will be the party's fifth leader in just four years.
Labour MPs, party members, and affiliated unions have had just under a month to cast a vote.
The contenders each made their case at 14 hustings meetings nationwide.
Voting closed at noon and a computer should've by now tallied and weighted the votes (40% caucus, 40% members, 20% unions) before spitting out the winner's name.