On Thursday the Supreme Court ruled against the Trump administration’s decision to end the Obama-era program that lets children of illegal aliens stay in this country virtually indefinitely. Chief Justice John Roberts, in a nuanced opinion, sided with liberals on the court, as he has on several prior occasions when important issues were at stake. The ruling is a political loss for the president and Trump expressed his displeasure over Twitter.

The Supremes ruled that the administration’s decision to end the Deferred Action on Childhood Arrivals (DACA) program violated the Administrative Procedure Act (APA), which establishes the procedures for federal agencies. In a 5-4 decision the court said the move to end the program was done in an “arbitrary and capricious” manner.

“We do not decide whether DACA or its rescission are sound policies. ‘The wisdom’ of those decisions ‘is none of our concern,'” Roberts wrote for the majority. “We address only whether the agency complied with the procedural requirement that it provide a reasoned explanation for its action.” He wrote that the administration “failed to consider the conspicuous issues of whether to retain forbearance,” as well as the impact the end of the program would have on DACA recipients who have relied on it. “That dual failure raises doubts about whether the agency appreciated the scope of its discretion or exercised that discretion in a reasonable manner. The appropriate recourse is therefore to remand to the DHS [Department of Homeland Security] so that it may consider the problem anew.”

“The dispute before the Court is not whether DHS may rescind DACA. All parties agree that it may,” wrote Chief Justice Roberts. “The dispute is instead primarily about the procedure the agency followed in doing so.” In stating “all parties agree that it may,” Roberts leaves the door open for further efforts at eliminating the program, just not in this way. “In short, the DACA Memorandum does not announce a passive non-enforcement policy; it created a program for conferring affirmative immigration relief,” Roberts concluded. “The creation of that program, and its rescission, is an ‘action [that] provides a focus for judicial review.'”

Justice Clarence Thomas dissented, “These cases could—and should—have ended with a determination that his legal conclusion was correct. Instead, the majority today concludes that DHS was required to do far more. Without grounding its position in either the APA or precedent, the majority declares that DHS was required to overlook DACA’s obvious legal deficiencies and provide additional policy reasons and justifications before restoring the rule of law. This holding is incorrect, and it will hamstring all future agency attempts to undo actions that exceed statutory authority. I would therefore reverse the judgments below and remand with instructions to dissolve the nationwide injunctions.”

Thursday morning, President Trump also retweeted a line from Thomas’ dissent, as did The Daily Caller: “Today’s decision must be recognized for what it is: an effort to avoid a politically controversial but legally correct decision.”