Protesters takes part in a rally to oppose a new Texas "sanctuary cities" bill that aligns with the president's tougher stance on illegal immigration in San Antonio June 26, 2017. (Eric Gay/AP)

A federal judge in Texas has temporarily blocked parts of a severe state immigration law that was supposed to take effect Friday and would have outlawed sanctuary cities and penalized local officials who do not cooperate with federal deportation efforts.

The decision Wednesday by U.S. District Judge Orlando Garcia in San Antonio delivers a temporary blow to the state’s campaign — backed by the Trump administration — to compel localities to detain immigrants so federal agents can take them into custody.

In a 94-page decision, Garcia wrote that parts of the Texas law are likely to be found unconstitutional. He enjoined the state from punishing local officials, infringing on their right to free speech and forcing them to detain immigrants for federal immigration officials, an act that is currently voluntary. And he wrote that cities and towns had provided “overwhelming” and “ample” evidence that cooperating with immigration officials will “erode public trust and make many communities and neighborhoods less safe” as well as harm the state economically.

“Indeed, at the end of the day, the Legislature is free to ignore the pleas of city and county officials, along with local police departments, who are in the trenches,” Garcia wrote. “The Court cannot and does not second guess the Legislature. However, the State may not exercise its authority in a manner that violates the United States Constitution.”

Gov. Greg Abbott (R) and Texas Attorney General Ken Paxton (R) vowed to appeal. “Today’s decision makes Texas’ communities less safe,” Abbott said in a statement.

The law would fine local officials who refused to assist federal agencies in working to deport illegal immigrants up to $25,500 a day. Elected and appointed officials could lose their jobs, and police and sheriffs could go to jail for up to a year on misdemeanor charges.

“The Court was right to strike down the guts of a law that is not only patently unconstitutional but bad policy as well,” said Lee Gelernt, an American Civil Liberties Union lawyer who argued against the case in court on behalf of several Texas cities and towns. “Hopefully other states will now not follow Texas’ lead.”

Garcia’s decision comes as Texas, home to an estimated 1.6 million undocumented immigrants, is grappling with historic flooding and dozens of deaths following Hurricane Harvey. It also lands amid growing fears that the Trump administration will end an Obama-era program that has granted nearly 800,000 immigrants brought to the United States as children reprieves from deportation.

Texas is one of 10 states that have threatened to sue the Trump administration if it does not begin to phase out the deportation-relief program by next week.

Abbott said the Texas statute would increase public safety by preventing local law enforcement from releasing foreign-born residents from jails or prisons before immigration agents can take them into custody.

The small border city of El Cenizo sued to stop the law, and was soon joined by Houston, San Antonio, Dallas, Austin and other cities. They said the law could lead to racial profiling, make immigrants afraid to report crime and ignite a backlash that could devastate the state economically.

The U.S. Justice Department sided with Texas in defending the law in federal court.

President Trump signed an executive order in January that threatened to withhold federal funds from sanctuary cities. A federal judge later halted that order, saying it was overly broad. The administration has continued to try to steer funding away from cities and towns that refuse to help enforce immigration law.

El Cenizo Mayor Raul Reyes said Wednesday’s ruling left him in tears, thinking about the hate-filled messages he’s received for filing the lawsuit, and the immigrants who will rest more easily come Friday — at least temporarily. “This is great news for thousands of families here in Texas,” he said.

Houston Mayor Sylvester Turner, who is touring flooded areas of the city, tweeted: “Happy to learn a federal judge blocked the Texas law aimed at making local police immigration enforcers. Need them for fighting local crime.”

Few localities in Texas actually declare themselves “sanctuaries” for undocumented immigrants, though many, including Houston, say they are “welcoming” cities and limit how frequently they will cooperate with federal immigration officials.

For instance, some are willing to hand over violent criminals, but unwilling to turn over someone arrested for a minor offense.

Garcia noted that localities have cooperated voluntarily with immigration officers for decades and may continue to do so.

But he ruled that the plaintiffs are likely to prevail on several of their claims.

For instance, he said the state law’s mandate that local authorities honor all federal requests to detain immigrants may violate the Fourth Amendment’s protection against being jailed without probable cause.

The court also found that the plaintiffs were likely to succeed on their claims that the law violated the First Amendment, by banning officials from endorsing sanctuary policies, and that it was unconstitutionally vague.

Garcia ruled that the mandates and penalties in the law go beyond what federal law requires and “upset the delicate balance between federal enforcement and local cooperation and violate the United States Constitution.”