Labour's Kris Faafoi has won the Mana by-election, but with a significantly reduced majority for the party.
The former television journalist and Labour press secretary was favourite to win the seat over National's Hekia Parata.
Faafoi got 10,397 votes, ahead of Parata who received 9,317 votes. Independent Matt McCarten came in fourth with 816 votes, behind the Green Party's Jan Logie on 1,493.
The turnout was about 40 percent, with a total 22,387 votes cast, well down on the last general election when more than 30,000 were counted.
Only two of the eight candidates, Logie and Act's Colin du Plessis, could cast a ballot because they live in the electorate.
The seat was previously held by Winnie Laban who won it for Labour in 2008 with a majority of some 6000.
Labour leader Phil Goff and Faafoi were greeted by a rapturous crowd of about 200 people at the election night venue. Goff said the result reflects well on Faafoi's hard work and is "one step on the way to getting back to a Labour government".
Faafoi vowed to work hard for all the people in Mana. He said he was there to represent the well off, as well as struggling families.
He said he was proud to be New Zealand's first Tokelauan Member of Parliament.
Parata said National ran a strong campaign and the party's policies resonated with the people in the electorate.
Prime Minister John Key said the result is a win for National and will put pressure on Goff's leadership of the Labour Party. Key was at National's election night headquarters to support Parata, along with several cabinet ministers, MPs and former ministers.
The Prime Minister said he never thought coming second would feel so good and Parata has taken a safe Labour seat and made it marginal.
But Faafoi said a win's a win and he was looking forward to increasing his majority in the general election next year.
Meanwhile police issued a warning against an independent running in the by-election, following up a complaint that McCarten breached electoral rules that no campaigning or advertising for a party is conducted on polling day.
The matter will be referred to the Electoral Commission.