Buying a home in New Zealand just got a lot tougher for most people.

The country's parliament on Wednesday passed a law banning foreigners from buying into most parts of its residential property market as the government seeks to cool red-hot house prices.

The Overseas Investment Amendment Bill will prevent overseas investors from purchasing existing properties in New Zealand, but they will still be able to buy into new apartment complexes and certain other parts of the housing market.

New Zealand Prime Minister Jacinda Ardern campaigned on a promise to clamp down on foreign buyers, blaming them for soaring prices that have left many New Zealanders unable to enter the property market.

"If you've got the right to live in New Zealand permanently, you've got the right to buy here," Trade Minister David Parker said during a final debate on the bill Wednesday. "We believe it's the birthright of New Zealanders to buy homes in New Zealand," he added.

Public policy firm Demographia regularly ranks Auckland, New Zealand's biggest city, as one of the world's least affordable places to buy a home.

House prices have almost doubled over the past decade, according to central bank data, and are up more than 5% so far this year. Home ownership rates among New Zealanders have also been falling in recent years.

But government data suggests that foreign buyers actually only make up a small part of the country's housing market. According to the latest official statistics, purchasers who don't hold New Zealand citizenship or residency make up less than 3% of total transactions.

Most foreign buyers in New Zealand don't state where they're from, official data shows, but the majority of those who do are from China.

New Zealand has also proved to be a popular retreat for the rich and famous. Billionaire investor Peter Thiel and disgraced former NBC host Matt Lauer both own properties in the country.

Related: New Zealand is going to start taxing tourists

Analysts say it's still unclear how much difference the new law will make.

"We simply do not know how it will affect the market," Dominick Stephens, chief economist at the New Zealand division of banking group Westpac, said in a note to clients Wednesday. House prices could stop rising before the end of the year or even begin falling, he predicted.

Nearby Australia has also tried to slow runaway house prices with measures including a similar ban on foreign investors buying existing properties. Prices in the country have been falling since the end of last year.

The new law in New Zealand doesn't apply to Australian and Singaporean buyers because of existing arrangements between the countries. It still needs to receive royal assent, which is a formality, before it comes into force.