A federal judge on Tuesday blocked President Trump's sanctuary cities executive order.

San Francisco and Santa Clara County both won preliminary injunctions on Tuesday against Trump's Jan. 25 executive order that moved to cut off federal funding from cities that limit their cooperation with federal immigration requests.

According to San Francisco-based U.S. District Judge William H. Orrick, the loss of funds would cause cities "to suffer irreparable harm absent an injunction."

Orrick also cited public comments from Trump and Attorney General Jeff Sessions, saying the two "erased" any "doubt about the scope of the order."

"The Constitution vests the spending power in Congress, not the president, so the order cannot constitutionally place new conditions on federal funds," Orrick wrote, calling the DOJ's arguments that it only wanted cities to show compliance with current immigration law "not legally plausible."

However, the federal government is still able to enforce existing conditions of federal grants and does not restrict it from "developing regulations or preparing guidance on designating a jurisdiction as a 'sanctuary jurisdiction,'" Orrick ruled.

There are at least five other city lawsuits against similar language in the executive order, including Seattle, Richmond, Calif., and two cities in Massachusetts.

Santa Clara County Supervisor Cindy Chavez called it a victory for immigrants.

"We're fighting for the United States Constitution and we succeeded after the Trump administration tried to do an end run around it," said Chavez in a statement. "The court's decision is a win for the neediest people in our nation. Seniors in need of food, foster youth in need of shelter and children who need medical care. We'll continue being a welcoming, safe and diverse community."

Santa Clara has said it gets $1.3 billion from federal funds, which was at risk. San Francisco stood to lose more than $1 billion in federal funds.

"This is why we have courts — to halt the overreach of a president and an attorney general who either don't understand the Constitution or chose to ignore it," said Dennis Herrera, the San Francisco city attorney, in a statement. "Because San Francisco took this president to court, we've been able to protect billions of dollars that fund lifesaving programs across this country."

The Trump administration has now seen three immigration orders stopped by federal courts in its first 100 days, including rulings against key portions of two of immigration-related executive orders.

The federal government has been taking actions targeting so-called sanctuary cities since the January executive order, such as rolling back Justice Department grants that a city can receive contingent on cooperating with immigration requests under Section 1373 of 8 U.S. Code.

In a statement, a Justice Department spokesman said the agency would continue to enforce the law in sanctuary cities in respects to U.S.C. 1373.

The DOJ "will follow the law with respect to regulation of sanctuary jurisdictions," said Ian Prior in a statement late Tuesday. "[T]he order does not purport to enjoin the Department's independent legal authority to enforce the requirements of federal law applicable to communities that violate federal immigration law or federal grant conditions."