Post-Brexit rules for millions of people in Britain have been declared unlawful by the High Court.
Campaigners hailed victory after a top judge ruled against part of the EU Settlement Scheme - set up for EU citizens in the UK.
Under the rules, EU citizens who had lived in Britain for more than five years by 31 December 2020 could apply for ‘settled status’.
But 2.6million who had been here less than five years could only apply for ‘pre-settled status’.
They then have to make a second application later on for settled status - and if they don’t, they could lose their rights.
The High Court heard this group risk becoming “illegal overstayers” overnight, as soon as August 2023.
Campaigners and the Independent Monitoring Authority, a government watchdog, argued this was ‘incompatible’ with Boris Johnson ’s Brexit deal.
Robert Palmer KC, for the claimants, said people who failed to make the second application would end up “liable to detention and removal."
And they would lose all rights of residence including the right to work, to rent a home and to access healthcare, he said.
Judge Mr Justice Lane concluded the Home Office had wrongly interpreted the law on both issues challenged by the IMA.
He said if the Home Office's interpretation of the law was correct, "a very large number of people face the most serious uncertainty".
IMA chief executive Dr Kathryn Chamberlain said: "When we brought this judicial review, our intention was to provide clarity for citizens with pre-settled status.
“This judgment that the current system is unlawful provides that clarity. We will now liaise with the Home Office on the next steps."
Rhys Davies, IMA general counsel, said: "The withdrawal and separation agreements say that people can only lose their rights in a limited set of circumstances.
“Failing to upgrade from pre-settled to settled status is not one of them.”
The case was supported by the European Commission and the3million, a grassroots organisation representing EU citizens in the UK.
Monique Hawkins of the3million warned EU citizens “could lose their right to work, rent, travel, benefits, healthcare and more - just for not making a further application in the years ahead.
She added: “Once a beneficiary, people cannot lose their rights just by forgetting to make a second UK immigration application.
“The withdrawal agreement does not allow it."
Home Office Minister Lord Murray said: "EU citizens are our friends and neighbours, and we take our obligations to securing their rights in the UK very seriously.
"The EU Settlement Scheme goes above and beyond our obligations under the withdrawal agreement, protecting EU citizens' rights and giving them a route to settlement in the UK.
"We are disappointed by this judgment, which we intend to appeal."