New Zealand has banned most foreigners from buying homes as it tries to tackle runaway housing prices.

The housing market had been open to investors worldwide, but the government on Wednesday passed legislation that allows only New Zealand residents to purchase homes.

In recent years, there have been many anecdotal stories of wealthy foreigners from Silicon Valley and beyond buying ranches in picturesque rural New Zealand as a "bolt hole" or escape option from a turbulent world.

We're here today to take another step toward restoring the great New Zealand dream of home ownership. - David Parker, associate finance minister

There have also been stories of wealthy Chinese buyers outbidding New Zealanders on suburban homes in the main city of Auckland.

Statistics indicate about three per cent of New Zealand homes are being sold to foreigners, but the amount rises to five per cent in the scenic Queenstown region and 22 per cent in central Auckland.

Last month, the directors of the International Monetary Fund executive board said they encouraged New Zealand to reconsider the ban, which they thought would be unlikely to improve housing affordability.

But the government says there is no doubt that foreigners are driving up prices, and the only question that remains is by how much. The new law fulfils a campaign pledge by the liberal-led government that came to power last year.

Exceptions for Australians, Singaporeans

There are some exceptions. Foreigners with New Zealand residency status will still be able to buy homes, as will people from Australia and Singapore, thanks to existing free-trade agreements.

Foreigners who already own homes in New Zealand won't be affected, and overseas buyers will still be able to make limited investments in large apartment blocks and hotels.

"We're here today to take another step toward restoring the great New Zealand dream of home ownership," said Associate Finance Minister David Parker.

He said it was the birthright of New Zealanders to buy homes at a fair price.

"This government believes that New Zealanders should not be outbid by wealthier foreign buyers," Parker said. "Whether it's a beautiful lakeside or oceanfront estate, or a modest suburban house, this law ensures that the market for our homes is set in New Zealand, not on the international market."

Opposition lawmaker Judith Collins said the bill was unnecessary.

"We oppose the bill because we don't believe that it actually fixes any problem. It is, in fact, nothing more than an attempt to justify some of the policies of the incoming government."

Skyrocketing home prices in Auckland have been of particular concern to New Zealanders, although that market has cooled over the past year. Still, prices there remain among the most expensive in the world when compared with people's incomes.

Figures released Wednesday by the Real Estate Institute of New Zealand indicate the median house price in Auckland is 835,000 in New Zealand dollars ($716,000 Cdn) while the median price across the country is $550,000 NZD ($473,000 Cdn).