A federal judge in San Francisco dealt the Trump administration another legal blow Tuesday, temporarily halting President Trump’s threat to withhold unspecified federal funding from cities and towns that refuse to cooperate with immigration authorities.

U.S. District Judge William H. Orrick imposed a nationwide injunction against Trump’s Jan. 25 executive order on what are called “sanctuary” jurisdictions and said lawsuits by Santa Clara County and San Francisco challenging the order were likely to succeed.

Orrick pointed to discrepancies in the administration’s interpretation of the executive order, which broadly authorized the attorney general to withhold grant money from jurisdictions that do not cooperate with immigration officials on deportations and other enforcement actions.

At the same time, the judge said the Justice Department may hold back grant money that is awarded with immigration-related conditions, if those conditions are violated. The department responded to the ruling by saying it could essentially continue to operate as it had been.

The judge’s decision largely blocks the administration from doing things its lawyers said in court the agency would not do, such as strip health-care funding from cities and towns.

(Claritza Jimenez/The Washington Post)

But the American Civil Liberties Union and other advocacy groups said the injunction offered a clear warning that Trump’s order — the third issued by the president to be blocked, at least partially, in federal court — is illegal.

“Once again, the courts have spoken to defend tolerance, diversity and inclusion from the illegal threats of the Trump administration,” ACLU National Political Director Faiz Shakir said in a statement. “Once again, Trump has overreached and lost.”

In a series of tweets Wednesday, Trump vowed that the White House was ready to bring the case to the Supreme Court and blasted the U.S. 9th Circuit Court of Appeals, which was part of legal decisions blocking Trump’s travel restrictions on several Muslim-majority countries.

“First the Ninth Circuit rules against the ban & now it hits again on sanctuary cities — both ridiculous rulings. See you in the Supreme Court!” Trump wrote.

Orrick is a federal district judge in San Francisco. He does not serve on the U.S. Court of Appeals for the 9th Circuit, though those judges would review his decisions.

In an earlier statement, the White House took aim at Orrick, saying his ruling “unilaterally rewrote immigration policy for our nation.”

“This case is yet one more example of egregious overreach by a single, unelected district judge,” the White House statement said.

In court, the government’s lawyers suggested cities and towns were overreacting to the order because federal officials have not yet defined sanctuary cities or moved to withhold funding from them. But on television and in news conferences, the judge pointed out, the president and Attorney General Jeff Sessions have threatened to sanction such jurisdictions.

“The result of this schizophrenic approach to the Order is that the Counties’ worst fears are not allayed and the Counties reasonably fear enforcement under the Order,” the judge wrote. “The threat of the Order and the uncertainty it is causing impermissibly interferes with the Counties’ ability to operate, to provide key services, to plan for the future, and to budget.”

Trump says sanctuary cities put Americans at risk by refusing to hold immigrants who have been arrested or convicted of serious crimes until immigration agents can take them into custody and deport them.

Sanctuary cities’ officials counter that they do not have the legal authority to hold a person after a judge in a criminal case has ordered that person released. Holding people on immigration offenses is generally a civil process, rather than a criminal one.

White House Chief of Staff Reince Priebus said Justice Department lawyers are reviewing legal options. “It’s the 9th Circuit going bananas,” he told reporters Tuesday evening. “The idea that an agency can’t put in some reasonable restriction on how some of these monies are spent is going to be overturned eventually, and we’ll win at the Supreme Court level at some point.”

San Francisco Mayor Edwin M. Lee (D) applauded Orrick’s ruling, saying his jurisdiction “is and will remain a Sanctuary City … If the federal government believes there is a need to detain a serious criminal, they can obtain a criminal warrant, which we will honor, as we always have.”

The ruling was also hailed by the U.S. Conference of Mayors, which had been told by Sessions hours earlier that officials must communicate with immigration officials under federal law.

“The Conference has long opposed the withholding of funds from so-called ‘sanctuary cities,’ which, of course, is a political term not a legal one,” executive director Tom Cochran said in a statement.

Matt Zapotosky, Philip Rucker and Brian Murphy contributed to this report.