New Zealand has passed legislation allowing its main intelligence agency to spy on residents and citizens, despite opposition from rights groups, international technology giants and the legal fraternity.

The bill to expand the power of the Government Communications Security Bureau (GCSB) passed by 61 votes to 59 after impassioned debate, with Prime Minister John Key acknowledging the move had left some people "agitated and alarmed".

"This is not, and never will be, about wholesale spying on New Zealanders," Mr Key told parliament.

"There are threats our government needs to protect New Zealanders from, those threats are real and ever-present and we underestimate them at our peril."

The push to change the law came after it emerged last year that the GCSB illegally spied on Internet tycoon Kim Dotcom before armed police raided his Auckland mansion as part of a US-led probe into online piracy.

At the time Mr Key publicly apologised to Mr Dotcom, who is a New Zealand resident and should have been off-limits to the GCSB under legislation preventing it from snooping on locals.

However, an official report found that Mr Dotcom's case was only one of dozens in which the GCSB had overstepped its bounds.

Mr Key then moved to change the law to let the GCSB spy on New Zealanders, arguing it needed to cooperate more closely with agencies such as the police and military in an increasingly complex cyber-security environment.

A year ago it came to light the GCSB had illegally spied on internet mogul and New Zealand resident Kim Dotcom. ( AFP: Michael Bradley )

Mr Dotcom has been one of the strongest opponents of the bill, saying it gives government spies legal access to New Zealanders' electronic communications, including mobile phone calls.

"This will be the birth of a surveillance state in New Zealand," he told a protest meeting in Auckland last weekend.

After Wednesday night's vote, Mr Dotcom predicted a backlash against Mr Key at next year's general election.

"The #GCSB bill just passed in Parliament against the will of most Kiwis. RIP Privacy. Payback at the 2014 election," he tweeted.

Global opposition

Tech giants such as Google, Facebook and Microsoft have also voiced concern about expanding the GCSB's surveillance powers.

"Blanket rules requiring data retention and accessibility are blunt tools, which have the potential to infringe on civil liberties and constrain economic growth," Facebook said in a submission to a parliamentary committee reviewing the bill.

New Zealand's Law Society, Human Rights Commission and Privacy Commission all made submissions raising concerns about the bill and calling for significant changes.

An opinion poll published in the Dominion Post newspaper on Wednesday found 75 per cent of respondents were concerned about the changes.

Mr Key dismissed such reservations, saying conspiracy theorists and his political opponents had whipped up an alarmist frenzy.

"I have rarely seen so much misinformation and conspiracy as has been perpetrated about this bill," he said.

"That has some citizens agitated and alarmed, which I regret.

But my regret would be nothing compared to the threat if this legislation was not passed and New Zealanders were harmed because of a gap that currently exists in our security arrangements."

AFP