A major plank of the UK's strategy for removing failed migrants has been ruled illegal because it prevents the courts from considering their cases.
In a significant ruling, the Court of Appeal said the policy risked removing people from the UK even if they had a right to be in the country.
The policy has been used in 40,000 removal cases.
Campaigners who brought the challenge said the Home Office had endangered lives by short-cutting the law.
The unanimous judgment against the Home Office was taken by the Lord Chief Justice, Lord Burnett, and two other senior judges.
It's not clear whether ministers will attempt to go to the Supreme Court but a Home Office spokesman said it is going to reform a failing immigration system.
The controversial policy which has been ruled illegal was introduced in 2015 in an attempt to prevent last-minute applications to stop removals - sometimes at the steps of the plane.
It has been suspended for 18 months during the legal battle. Removals have been carrying on under a far slower and complicated procedure that allows more time for appeals.
Under the 2015 policy, officials told failed applicants - whether they were asylum seekers, economic migrants or people making other claims - that they had 72 hours to make final representations. After that, they could be flown out of the UK, without notice, on any date in the following three months.
Charity Medical Justice said the rules meant people with a genuine case to be in the UK simply could not present their arguments in time to a judge.
In examples submitted to the court, the charity said the Home Office had repeatedly removed people - only to bring them back again.
In one case, a man who had evidence that relatives had been murdered in his home country, had to be flown back to the UK and he was later found to be a genuine refugee.
The three Court of Appeal judges said the Home Office's aspiration to speed up removals was not in itself illegal - but in practice the policy had prevented effective appeals and that had risked serious injustices.
"The right to access the court is an absolute and inviolable right," said the court.
"The right to access to the court is not a relative right to be balanced against other rights and interests, the convenience of the executive or the courts, or the risks of abuse of process."
False and fanciful claims
Home Secretary Priti Patel has repeatedly accused what she has called "activist lawyers" of slowing down immigration removals.
And in the judgment, the Lord Chief Justice said there were "endemic" problems of false and fanciful late claims, some of which involved a "minority of lawyers", unconnected to the case before them.
But the judges stressed that the Home Office's solution had prevented judges from considering genuine cases because someone could be put on a flight before they had had a chance to go to court.
A spokesman for Medical Justice said the policy had unfairly treated many of its sick clients.
"One of our society's most precious treasures is access to justice," said the spokesman.
"Chillingly, away from the public gaze, this policy denied that fundamental right on a massive scale causing serious harm to extremely vulnerable people and risking life.
"It was effectively a shortcut to removal. Quashing the policy brings us back towards equal access to justice for all."