Nine Law Lords have ruled that the government's detention of terror suspects without trial breaches human rights laws.
Ministers have been braced for this defeat since hearings were held before the lords in October.
The decision is an unwelcome present for Charles Clarke
Attorney General Lord Goldsmith, who presented the government's case, was privately gloomy about the prospects of success, knowing that a law which discriminates against foreign-born detainees strikes at the heart of ancient legal safeguards against arbitrary arrest.
Lord Goldsmith's argument had two limbs.
That the nature of the terrorist threat post-11 September was so severe as to justify exceptional measures, such as opting out of Article 5 of the European Human Rights Convention.
And that the Anti-Terrorism, Crime and Security Act 2001 provided processes for reviewing the legality of detentions without trial.
In the event, the Court of Appeal concluded that the legislation was lawful. But crucially, the highest court has not - and it is one of its most significant judgments of recent times.
So, what now? In the United States, a ruling of similar magnitude by the Supreme Court meant automatically that Guantanamo captives can challenge their detention in the courts.
But the House of Lords does not have primacy over the executive and the government must now decide if it wishes to take its case to parliament for a second time.
The alternative is to frame new legislation which would put foreign-born suspects on exactly the same footing as British citizens and allow them to be tried on terror charges.
Outgoing Home Secretary David Blunkett - replaced by Charles Clarke a day before the lords' ruling - had been planning new laws to permit the use of phone-tap evidence in trials and to set up special anti-terror courts without juries and with the participation of lawyers who have security clearance.
Such a controversial measure would have to await the election and, even then, it would probably have a stormy passage through parliament.
Fear of torture
The pressing question then is what happens to the detainees in Belmarsh?
One has already been released and is subject to a form of house arrest. It is possible that a similar procedure could be followed with those considered too dangerous to free unconditionally.
But that, too, is bound to provoke a legal challenge.
There may be renewed efforts to find countries which might take those suspects who refuse to return to their homelands for fear of torture or death.
But that may be a forlorn hope. For the government, it is a major headache which must be addressed urgently.
Cynics will suspect that Mr Blunkett decided to step down on Wednesday knowing that he had been defeated on a crucial plank of policy.
And that would have been one setback too many to recover from.