A federal judge on Tuesday dealt another blow to President Trump’s agenda — ruling that the administration can’t force “sanctuary cities” like the Big Apple to cooperate with immigration officers by withholding federal funds.

California US District Judge William Orrick issued the temporary ruling saying that Trump had no authority to attach new conditions to federal spending.

His ruling came in a lawsuit filed by San Francisco and Santa Clara County against the executive order.

The plaintiffs argued during an April 14 hearing that it threatened billions of dollars in federal funding for each of them, making it difficult to plan their budgets.

Federal law doesn’t define “sanctuary cities,” and the Trump administration had given differing descriptions of the policies it was looking to enforce.

More than 300 cities and counties nationwide have placed limits on how far their law enforcement agencies are allowed to cooperate with federal immigration officials looking to detain and deport immigrants for crimes in or illegal entry to the US.

“The Counties have demonstrated that they are likely to succeed on the merits of their … challenge to the Executive Order, that they will suffer irreparable harm absent an injunction, and that the balance of harms and public interest weigh in their favor,” Orrick wrote.

The decision will stay in place while the lawsuit works its way through court.

“It’s not like it’s just some small amount of money,” John Keker, an attorney for Santa Clara County, told Orrick, a President Obama appointee, at the April 14 hearing.

Chad Readler, acting assistant attorney general, said the county and San Francisco were interpreting the executive order too broadly.

The funding cutoff applies to three Justice Department and Homeland Security Department grants that require complying with a federal law that local governments not block officials from providing people’s immigration status, he said.

The order would affect less than $1 million in funding for Santa Clara County and possibly no money for San Francisco, Readler said.

Trump was using a “bully pulpit” to “encourage communities and states to comply with the law,” Readler said.

In his ruling, Orrick sided with San Francisco and Santa Clara, saying the order, “by its plain language, attempts to reach all federal grants, not merely the three mentioned at the hearing.”

“The rest of the order is broader still, addressing all federal funding,” Orrick said. “And if there was doubt about the scope of the order, the president and attorney general have erased it with their public comments.”

The judge said: “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.”

The ruling came as Team Trump had been crowing about the administration’s achievements during his first hundred days in office and will give critics more ammunition for their arguments that he had actually accomplished next to nothing. His 100th day in office will be Saturday.

Opponents like Rep. Nydia M. Velázquez (D-NY) hailed the ruling.

“New York has made clear that we will not be an accomplice to implementing anti-immigrant policies that tear apart families and sew fear in our communities. Today’s ruling is a positive step toward reversing this unlawful Executive Order, which we will continue to resist through every available avenue,” she said in a statement.

The Trump administration argued that sanctuary cities allow dangerous criminals back on the street and that the order is needed to keep the country safe.

New York, San Francisco and other sanctuary cities replied that turning local police into immigration officers erodes trust that’s needed to get people to report crime.

The order also has led to lawsuits by Seattle; two Massachusetts cities, Lawrence and Chelsea; and a third San Francisco Bay Area government, the city of Richmond. The San Francisco and Santa Clara County suits were the first to get a hearing before a judge.

The Department of Justice declined to say whether the ruling would be appealed. But a spokesman said the decision still permits the Justice Department to require jurisdictions like New York City to certify compliance with federal immigration laws in order to receive federal grants.

“The department will continue to enforce existing grant conditions and will continue to enforce 8 U.S.C. 1373,” Ian Prior, a Justice Department spokesman, said in a statement, referring to the federal law that says localities can’t prohibit information sharing with immigration agents.

With AP