Rules aimed at preventing illegal immigrants from renting properties are "discriminatory" and breach human rights laws, the High Court has ruled.
The "right to rent" scheme, which requires landlords to check the immigration status of tenants, was introduced in England in 2016.
Judges said it would be illegal to roll it out in Scotland, Wales and Northern Ireland without further evaluation.
The Home Office said it was "disappointed" by the ruling.
Mr Justice Spencer said the scheme had "little or no effect" on its main aim of controlling immigration and even if it had, this was "significantly outweighed by the discriminatory effect".
He added that the evidence "strongly showed" the scheme was causing landlords to discriminate against potential tenants because of their nationality and ethnicity.
The scheme, the judge said in his ruling, appeared to be having a "real effect" on people's ability to find accommodation and the MPs who voted for it "would be aghast" to see its consequences.
The challenge was brought by the Joint Council for the Welfare of Immigrants (JCWI), which claimed the scheme was "race discrimination against those who are perfectly entitled to rent".
Responding to the ruling, legal policy director Chai Patel said there was "no place for racism in the UK housing market".
He added that the judgement "only reveals the tip of the iceberg" and called on Parliament to scrap the policy.
The Residential Landlords Association also welcomed the ruling and said the policy had turned landlords into "untrained and unwilling border police".
The group said its research had found that fear of getting things wrong led to private landlords being less likely to rent to those without a British passport or those with limited time to remain in the UK.
The Home Office said an independent study found no evidence of systematic discrimination in its policy and the scheme was intended to discourage illegal residence in the UK.
It said it had been granted permission to appeal and was giving careful consideration to the judge's comments.
By Clive Coleman, BBC legal correspondent
Discrimination cases are very difficult to win.
What was critical in this case was the independent evidence of discrimination, including that gathered by the Joint Council for the Welfare of Immigrants in two mystery shopping exercises where identical applications were made to landlords but with key details such as names changed.
The aim was to determine whether decisions were being made on the basis of ethnicity or nationality.
Where people could provide a UK passport, there was no evidence of ethnicity discrimination.
However, when they could not, the person with an ethnic name was less successful in gaining a tenancy than the one with a white British name. This showed that landlords concerned about a possible prosecution under the right to rent scheme were looking at ethnicity as a means of refusing prospective tenants.
That is what led Mr Justice Spencer to conclude the scheme "does not merely provide the occasion or opportunity for private landlords to discriminate but causes them to do so where otherwise they would not", describing such discrimination by landlords a being "logical and wholly predicable" when faced with potential sanctions and penalties for getting things wrong.
'Hostile environment' policy
The "right to rent" scheme, which was first trialled in the West Midlands, requires landlords to carry out checks on prospective tenants, such as seeing their passport or visa.
Failing to do so is a criminal offence, carrying a maximum penalty of five years' imprisonment or a fine.
The scheme is part of the government's "hostile environment" policy, which aimed to reduce the number of illegal immigrants in the UK, and was introduced under the 2014 Immigration Act.
Lara ten Caten, a solicitor with Liberty, which intervened in the case, said the judgement was "another nail in the coffin for the government's misguided, discriminatory and unworkable hostile environment policy".
"While effective immigration control is a legitimate aim for any government, the Home Office must stop outsourcing its discriminatory policies to third parties who are ill-equipped to enforce them but may be slapped with heavy fines and even end up in prison if they don't," she said.
'Rule needs to be scrapped'
Mohamed, who did not wish to use his surname, says the right to rent checks proved an "extremely difficult hurdle" in his search for a London home.
He is British and his wife is legally in the UK on a spouse visa.
But Mohamed says they were turned down numerous times before eventually finding accommodation because landlords appeared worried about falling foul of the Home Office regulations.
"The rule needs to be scrapped," he adds. "Finding affordable rental property is difficult enough for people without the added hassle of being refused for no other reason than being foreign."