A federal judge Monday ruled that President Donald Trump’s order to restrict grants to cities that limit cooperation with U.S. immigration authorities was “unconstitutional.”

U.S. District Court Judge William Orrick permanently blocked Trump's  executive order to cut funding for the so-called sanctuary cities in lawsuits brought by two California counties: San Francisco and Santa Clara.

Suing over the order, the counties argued that more than $2 billion in federal funding could be at stake, reported the Hill.

Trump issued the order which slashed funding to local governments that refused share information about illegal immigrants with U.S. immigration authorities in January.

Following this, the Department of Justice (DOJ) sought to crackdown on cities and other local jurisdictions that had joined a “sanctuary” movement which attempted to  shield illegal immigrants from increasing deportation efforts.

The Byrne Justice Assistance Grant funding — the largest source of federal funding for criminal justice for state, local, and tribal authorities — could only be disbursed after the government complied with Section 1373 which was a federal statute regulating local cooperation with federal immigration officials, RT reported.

"The defendants are permanently enjoined from enforcing Section 9(a) of the Executive Order against jurisdictions they deem as sanctuary jurisdictions. Because Section 9(a) is unconstitutional on its face, and not simply in its application to the plaintiffs here, a nationwide injunction against the defendants other than President Trump is appropriate," judge Orrick ruled Monday.

The ruling to ban the order permanently comes after a previous ruling by Orrick in April in which he put a temporary hold on Trump’s decision to crackdown on the sanctuary cities.

Orrick, in a statement about his ruling, also said: “…the Executive Order was meant  to be far more narrow than I interpreted it, a mere directive to the Department of Homeland  Security and the Department of Justice that does not seek to place any new conditions on federal funds.”

"I concluded that the County of Santa Clara and the City and County of San Francisco had pre-enforcement standing to protect hundreds of millions of dollars of federal grants from the unconstitutionally broad sweep of the Executive Order," Orrick wrote.

San Francisco City Attorney Dennis Herrera said the ruling was “a victory for the American people and the rule of law.”

“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, thestar.com reported.

A DOJ lawyer argued during a hearing before Orrick in April that Trump’s executive order applied to only a few grants and would affect less than $1 million for Santa Clara County and possibly no money for San Francisco. However, the federal judge said the order potentially endangered hundreds of millions of dollars in funding to the two California counties.

Orrick reportedly cited comments by Trump and Attorney General Jeff Sessions as evidence that a number of federal funding initiatives were intended to be targeted by the order.

Last week, Sessions sent a memo giving 29 jurisdictions until December 8 to comply with federal laws or lose federal funding. Thirteen of the jurisdictions that received the compliance letters are in California: Berkeley, Los Angeles, Fremont, Santa Ana, Watsonville, the city and county of San Francisco, and the counties of Contra Costa, Riverside, Sacramento, Santa Clara, Sonoma and Monterey, RT reported.