The Trump administration has vowed to overturn a federal judge's decision to block President Trump's executive order cutting off federal funds to sanctuary cities, counties, and states.

A federal judge in Northern California determined Monday that Trump cannot place new conditions on spending Congress has approved. The judge's ruling responded to lawsuits brought by two California counties, San Francisco and Santa Clara, taking exception to Trump's threat to cut off federal grants to localities that limit law enforcement's cooperation with U.S. immigration authorities.

The Justice Department late Monday countered that cities, counties, and states do not have the ability to flout federal law and continue receiving federal money without any repercussions.

"The District Court exceeded its authority today when it barred the president from instructing his cabinet members to enforce existing law," said Justice Department spokeswoman Devin O'Malley. "The Justice Department will vindicate the president's lawful authority to direct the executive branch."

The judge's ruling aims to prevent Trump from following through with a January executive order designed to crack down on sanctuary cities and broader localities that refuse to comply with Immigration and Customs Enforcement (ICE) requests to hold immigrants arrested or convicted of crimes until federal authorities can pick them up.

California's legislature passed a law in October making the entire state a sanctuary for illegal immigrants. The law is California Democrats' latest salvo in its war with Trump over immigration policy.

Chicago and New York have also refused to comply with federal ICE requests.

U.S. District Judge William Horsley Orrick III, who former President Obama appointed to the bench, rejected the administration's argument that the federal grants in questions represented a small amount of money and therefore did not threaten state's rights guaranteed by the Constitution.

Instead, Orrick said the executive order was written in a sweeping way to "reach all federal grants," citing remarks Attorney General Jeff Sessions had made saying that the threat to pull funding was not limited to a narrow set of grants.

He also referred to comments Trump made about his own order, calling it a "weapon" against localities that reject federal law.

A Department of Justice lawyer in April said the threat to pull federal money only applied to a few federal grants for less than a million dollars for Santa Clara County and even less for San Francisco.

San Francisco City Attorney Dennis Herrera hailed the ruling as a "victory for the American people and the rule of law.

"This executive order was unconstitutional before the ink on it was even dry," he said in a statement.

"President Trump might be able to tweet whatever comes to mind, but he can't grant himself new authority because he feels like it."

The vast majority of California's sheriffs oppose the law, and the California State Sheriffs' Association has called on the GOP-controlled Congress to intervene and pass a federal law to change the state's sanctuary status.

Sheriffs said the law would prevent police from notifying ICE of self-admitted members of MS-13 or other gangs if they were arrested for misdemeanor crimes such as assault and battery, possession of narcotics, being under the influence of narcotics, or driving without a license.

Police also worry that the law is too lenient on illegal immigrants who have been arrested for drunk driving. Police can only call federal immigration authorities if they arrest an illegal immigrant with a violent felony on his or her record. In California, a person must be convicted on drunk-driving charges four times in a decade for it to be considered a felony, law enforcement sources said.

They have repeatedly predicted that the law will open the door to another high-profile tragedy similar to Kathryn "Kate" Steinle's death in 2015 at the hand of an illegal immigrant who had been deported a total of five times.