For 18 months the government has battled to make its Rwanda plan a reality - at the cost of £140m in payments to the African nation. Now, it's looking at the wider legal and political damage of seeing it torn to shreds in a highly-critical Supreme Court judgement.
Hours later, Rishi Sunak declared he already had a plan to solve it.
"It's like a boxer who just got knocked out, wanting a rematch immediately," one of the lawyers who defeated the government told me.
It is very difficult to see how Mr Sunak can turn this situation around in the time that he has left before a general election.
The prime minister told Parliament the court had "confirmed that the principle of removing asylum seekers to a safe third country is lawful. There are further elements that they want additional certainty on".
This is not what the court said.
It was never asked to rule on the general legal principle of sending people to countries deemed to be safe.
And the five justices did not send a memo asking for "additional certainty". The phrase does not appear in their judgement. They ruled the current plan was unlawful and shoved it in the legal shredder.
If the government comes back with a better plan, as with all such cases, it would be assessed on its merits.
So why was the Rwanda scheme unlawful?
The judgement found that the High Court - the first stage upon which this legal saga has played out - had failed to do its job in assessing for itself whether or not there was a real risk that any genuine refugee sent to Rwanda could ultimately be sent back to the country they had fled from.
Sending someone back to where they could be tortured is called "refoulement".
The Supreme Court said the evidence showed the government had broken this rule in more ways than one because the evidence pointed to serious problems with the fairness and justice of the Rwandan system.
It added that the government had not only breached the ban on inhumane treatment under the European Convention on Human Rights, but also safeguards in three British laws passed by Parliament over the last 30 years.
The justices said that ministers and the High Court should have considered more seriously evidence of abuses from the UN - and, if they had, they would have concluded the risks were too great.
So how does the government go about changing the facts on the ground?
Home Office teams have been working pretty non-stop on this plan for 18 months - and that's included sending refugee system experts to Rwanda to help it improve how it treats cases. The government is paying for training and other support and all of this could, obviously, help.
The government is also promising a new treaty with Rwanda that will guarantee that anyone sent to the country would not be sent back to their home country. But we don't know what the final wording of that treaty will be or when it will be delivered and in operation.
In other words, a lot must change before the critical evidence of past abuses becomes legally irrelevant.
But what about changing the law?
Mr Sunak said he is prepared to change any domestic laws or international relationships that block the plans.
This is harder than it sounds. The UK doesn't have some kind of trump card to unilaterally change international relationships such as the Refugee Convention.
British laws can of course be changed by a vote in Parliament - and that's why the PM says he will introduce legislation to declare Rwanda a safe country.
Is this a workable plan?
Lord Jonathan Sumption, a former Supreme Court judge and often a critic of the European Court of Human Rights, said the prime minister's plan was "profoundly discreditable".
"If the courts are told [by an Act of Parliament] that they've got to pretend that Rwanda is safe, whether it is or not, then that will work domestically," he told the BBC.
"But it won't work internationally. It will still be a breach of the government's international law obligations.
"It will be a breach of the refugee treaty. It will be a breach of the rules of customary international law which the government has been promoting and saying covers this obligation for some years."
Lord Sumption said it was unlikely that the bill could get through the House of Lords where a lot of the expert work is done in finessing complex new legislation.
"It would be constitutionally a completely extraordinary thing to do, to effectively overrule a decision on the facts, on the evidence, by the highest court in the land."