Legislation forcing telecommunications firms to allow interception equipment to be installed on their networks passes by two votes

New Zealand's parliament has narrowly passed new legislation compelling telecommunication companies to allow the intelligence agencies to access customers' emails, texts and phone calls.

Under the telecommunications interceptions and security capability bill, firms must also consult with the electronic eavesdropping agency, the Government Communications Security Bureau, (GCSB), when developing new infrastructure and networks, and allow interception equipment to be installed on their networks.

The law, which passed by 61 votes to 59, would give GCSB powers similar to Britain's Government Communications Headquarters (GCHQ) and the US National Security Agency (NSA). Along with the Australian and Canadian intelligence agencies, GCSB shares large amounts of data with its US and UK counterparts through the "Five Eyes" electronic espionage alliance.

"Essentially signing up to this legislation is part of the price for membership of the Five Eyes network," said the Green party co-leader, Russel Norman, according to Fairfax New Zealand News. The Greens have called for an inquiry by the Independent Police Conduct Authority into GCSB spying.

Grant Robertson, an opposition Labour spokesman on security and intelligence, said: "What is being becoming clear globally is that it appears that [GCSB] is being used to do things that New Zealanders would not be comfortable with."

The prime minister, John Key, has refused to reveal the extent of data-sharing between GCSB and the Five Eyes network. Asked last week if the GCSB might have been involved in spying on other foreign leaders on the NSA's behalf, Key said: "I'm not going through what we are engaged in and what we are not because that has been our standard long-term practice of every prime minister. But what I can tell you is that whatever we do is lawful."

The communications minister, Amy Adams, said the bill would "safeguard public safety and security''.

"This will be done by ensuring that it is technically and practically possible for surveillance agencies to intercept communications, where there is a warrant or other lawful authority to do so, and by introducing a formal framework to ensure the security of our telecommunications networks," Adams said.

It is not clear whether such warrants can be used to give blanket permission for GCSB to intercept the internet and phone traffic of millions of people, as is the case in GCHQ's Tempora programme, and a variety of NSA operations.

Last week, the New Zealand defence minister, Jonathan Coleman, said he was "not worried at all" about revelations that the NSA had spied on world leaders.

At a Washington press conference with the US defence secretary, Chuck Hagel, Coleman said: "We don't believe it would be occurring. And, look, quite frankly, there'd be nothing that anyone could hear in our private conversations that we wouldn't be prepared to share publicly."