Protesters gather outside a courthouse in San Francisco in April before arguments in the first lawsuit challenging President Trump’s executive order on so-called sanctuary cities. (Haven Daley/AP)

A federal judge issued an injunction to permanently block President Trump’s executive order to deny funding to cities that refused to cooperate with federal immigration officials, after finding the order unconstitutional.

The ruling by District Judge William H. Orrick in San Francisco comes in response to a lawsuit filed by the city of San Francisco and nearby Santa Clara County and follows a temporary halt on the order that the judge issued in April.

Orrick, in his summary of the case Monday, found that the Trump administration’s efforts to move local officials to cooperate with its efforts to deport undocumented immigrants violated the separation of powers doctrine as well as the Fifth and Tenth amendments.

“The Constitution vests the spending powers in Congress, not the President, so the Executive Order cannot constitutionally place new conditions on federal funds. Further, the Tenth Amendment requires that conditions on federal funds be unambiguous and timely made; that they bear some relation to the funds at issue; and that they not be unduly coercive,” the judge wrote. “Federal funding that bears no meaningful relationship to immigration enforcement cannot be threatened merely because a jurisdiction chooses an immigration enforcement strategy of which the President disapproves.”

President Trump has threatened to go after sanctuary cities, which provide protections for illegal immigrants. (Claritza Jimenez/The Washington Post)

In court earlier this year, the government’s lawyers had said that cities were overreacting to the order because federal officials had not yet moved to withhold funding from them.

The ruling marks another blow to the Trump administration by the judicial branch. Other federal judges have reined in the administration’s travel ban after questioning its constitutionality. Those rulings are still winding their way through federal appeals courts.

San Francisco City Attorney Dennis Herrera described Orrick’s decision as a victory for the “rule of law.”

“No one is above the law, including the president. President Trump might be able to tweet whatever comes to mind, but he can’t grant himself new authority because he feels like it,” he said in a statement. “This case is a check on the president’s abuse of power, which is exactly what the framers of the Constitution had in mind.”

The executive order on so-called sanctuary cities was issued just days after Trump took office in January, and sought to withhold funds from cities that chose not to cooperate with federal efforts to deport undocumented immigrants. It’s constitutionality, or lack thereof, was the subject of instant debate at the time.

When Orrick issued the preliminary injunction — a temporary block of the order — in the summer, Trump lashed out on Twitter, grouping the decision with orders that had blocked his travel ban, and calling it “ridiculous.” The White House issued a statement that called it a  “gift” to gangs that puts “thousands of innocent lives at risk.”

As other judges did when assessing the travel ban, Orrick took into account the statements of the president, as well as those of Attorney General Jeff Sessions and others in the administration, to assess its intent and purpose.

“And if there was doubt about the scope of the Executive Order, the President and Attorney General erased it with their public comments,” Orrick wrote. “The President has called it ‘a weapon’ to use against jurisdictions that disagree with his preferred policies of immigration enforcement, and his press secretary reiterated that the President intends to ensure that ‘counties and other institutions that remain sanctuary cities don’t get federal government funding in compliance with the executive order.’ ”

Sessions had issued a memorandum that attempted to clarify the executive order in May; Orrick found that the memo amounted to “nothing more than an illusory promise to enforce the Executive Order narrowly.”

“To fix the constitutional problems I have identified, the Executive Order itself would need to be amended,” the judge wrote.

The Department of Justice did not immediately respond to a request for comment about whether it planned to appeal the ruling.

Trump has said that 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.

In a release about the decision, Herrera noted that San Francisco complies with federal immigration enforcement.

“The federal government has always been free to enforce immigration law in San Francisco, just like it can anywhere else in the country,” he wrote. “But our teachers, doctors and police officers cannot be conscripted into becoming immigration agents. San Francisco’s sanctuary policies make our city safer by encouraging anyone who has been a victim or witness to a crime to tell police.”

President-elect Donald Trump pledged to end "sanctuary cities" while campaigning for the White House. Washington, D.C., is one such city. Here's what that means and how D.C. is trying to fight Trump's stance. (Claritza Jimenez/The Washington Post)

Heidi Li Feldman, a professor of law at Georgetown University, called the judge’s ruling a “recognition of the lawlessness” of the order.

“What is amazing about this is the thoroughness with which he dismisses the executive order,” she said. “The major ways in which an executive action can fail to be constitutional are all included in this suit, and Orrick is accepting the argument that literally every way the executive branch could violate the Constitution with regard to municipalities, this administration has.”

Maria Sacchetti contributed reporting. 

Read more:

How sanctuary cities work, and how Trump’s stalled executive order might affect them

The president attacked her son. So Marshawn Lynch’s mother fired back.