The law, which passed late on Wednesday, meets a key campaign pledge from Prime Minister Jacinda Ardern, who vowed to make housing more affordable before her election last year.
The new restrictions mean an almost complete ban on non-nationals buying residential property in New Zealand, with only a couple of exemptions.
“This is a significant milestone and demonstrates this government’s commitment to making the dream of homeownership a reality for more New Zealanders,” Associate Finance Minister David Parker said.
He added that the change “ensures that the market for our homes is set in New Zealand, not on the international markets”.
New Zealanders generally prefer to own their own homes, rather than rent, but record migration levels and a shortage of housing stock have driven up prices.
A government report earlier this year found house prices had risen 30 percent in the past five years, outstripping income increases by two to one, rising to four to one in the country’s largest city, Auckland.
As a result, it said homeownership had slipped to a 60-year low.
Ardern’s centre-left government says foreign buyers are a large part of the problem because they outbid locals.
In the past, it has singled out Chinese buyers as a major driver in the Auckland market, sparking allegations of racism from critics.
The new rules will prevent foreigners living in countries such as China, the main source of foreign buyers, from buying homes in New Zealand.
However, Australians, the second most common foreign buyers, will be exempt due to free trade agreements, as will Singaporeans.
New Zealand’s remoteness, once considered a hurdle for buyers, has also made it popular for ultra-rich foreigners looking for a bolthole.
They include US tech titan Peter Thiel, director James Cameron, Russian steel magnate Alexander Abramov and US broadcaster Matt Lauer.
Parker specified the new rules would apply “whether it’s a beautiful lakeside or oceanfront estate, or a modest suburban house”.
Real Estate Institute of New Zealand chief executive Bindi Norwell questioned the need for the new rules, saying foreign buyers only made up a small portion of the market.
“We don’t believe that banning foreign buyers from purchasing property in New Zealand is going to have any impact on house prices, nor will it help young people into their first homes,” she told stuff.co.nz.