AUSTIN, Texas ― A federal judge on Wednesday blocked most of a state immigration crackdown two days before it was set to go into effect on Sept. 1, offering a major victory for opponents as a tropical storm ravages the state and local officials struggle to assure immigrants it’s safe to seek help.

U.S. District Judge Orlando Garcia issued an injunction that prevents Texas Senate Bill 4 from being implemented while a lawsuit challenging the law winds its way through the federal courts. The ruling marks a victory for immigrant rights groups and several local governments ― including those of Austin, Houston, San Antonio and El Cenizo ― that argued the law unconstitutionally requires police to do the work of federal authorities and would lead to racial profiling.

“There is overwhelming evidence by local officials, including local law enforcement, that SB 4 will erode public trust and make many communities and neighborhoods less safe,” Garcia wrote in his order. “There is also ample evidence that localities will suffer adverse economic consequences which, in turn, harm the State of Texas.”

The judge added that the legislature “is free to ignore the pleas of city and county officials, along with local police departments, who are in the trenches and neighborhoods enforcing the law on a daily and continuing basis” and can disregard their “reservoir of knowledge and experience.”

“The Court cannot and does not second guess the Legislature,” Garcia wrote. “However, the State may not exercise its authority in a manner that violates the United States Constitution.”

The injunction isn’t a total victory for SB 4 opponents. The ruling allows a provision of the law to take effect authorizing police to ask about the immigration status of those they stop, which Garcia said could in theory be applied in a way that does not violate the Constitution.

Texas Attorney General Ken Paxton, a Republican, said in a statement he was confident federal courts will ultimately find the law constitutional and allow the state to implement it in full, despite the injunction.

“Senate Bill 4 was passed by the Texas Legislature to set a statewide policy of cooperation with federal immigration authorities enforcing our nation’s immigration laws,” Paxton said. “Texas has the sovereign authority and responsibility to protect the safety and welfare of its citizens.”

Gov. Greg Abbott (R) and other state Republican leaders viewed SB 4 as a priority at this year’s recently concluded legislative session. The law forbids localities’ so-called sanctuary policies that attempt to shield undocumented immigrants from deportation by limiting cooperation with federal immigration authorities.

Texas Republicans attempted to pass a law banning sanctuary cities for years without success before Abbott signed SB 4 in May. The state’s GOP majority dismissed objections from top law enforcement officials in several of the state’s largest cities, who said the measure would make immigrants ― both documented and undocumented ― reluctant to report crimes to the police out of fears of exposing themselves or their families to deportation.

Austin Mayor Steve Adler (D) applauded the ruling, and said this week’s devastating storm shows why it’s so important for communities to feel safe interacting with police and other authorities.

“If people in Austin do not feel safe asking for help, they become more vulnerable to crime, not just natural disasters,” Adler said in a statement.

The law would make it a misdemeanor, punishable by up to one year in jail, for local officials to enact policies that limit cooperation with the federal government’s deportation efforts. The law also would allow police officers to ask about the immigration status of the people they stop for other reasons, including traffic stops, drawing comparisons to Arizona’s 2010 “show me your papers” law that the Supreme Court gutted in 2012.

Lawyers representing local governments challenging the law argued that holding undocumented immigrants in custody at the request of Immigration and Customs Enforcement would violate the Fourth Amendment’s guarantee against illegal search and seizure.

ICE requests to hold undocumented immigrants are voluntary. Some federal judges, including Garcia, have ruled in the past against keeping someone in a local jail who would otherwise be freed because charges were dropped or because they qualified for release on bond.

The lawsuit against the Texas GOP’s immigration crackdown also contends that SB 4 violates the 14th Amendment’s equal protection clause, and forces local authorities to do a job reserved exclusively for the federal government. States cannot establish their own immigration policies, and no federal law imposes criminal penalties for disregarding voluntary requests from ICE to keep people detained.

The resolution on the constitutionality of SB 4 could have ripple effects around the country, said Roger C. Rocha Jr., president of the League of United Latin American Citizens, which helped bring the lawsuit.

“If eventually the courts rule in the state’s favor, then we know that other states will duplicate this law across the country,” Rocha said in an interview after the ruling. “So we know that this is ground zero. The fight is not over, we have to do our due diligence, and I actually see this going all the way to the Supreme Court.”