HOUSTON — A federal judge in San Antonio on Wednesday blocked Texas from enforcing its ban on so-called sanctuary cities, questioning the constitutionality of a law that has pitted Republican state leaders against several Democratic-leaning cities.

The judge’s ruling was only temporary, and prevents the law from taking effect on Friday while a suit against it goes forward. But the decision, which Texas said it would appeal, served as a legal blow to one of the toughest state-issued immigration laws in the country and puts the brakes on a measure backed by the Trump administration that critics had called anti-Latino. The law has become so divisive that it served as the backdrop of a shoving match at the Texas Capitol between Hispanic Democratic lawmakers and their white Republican colleagues.

The law, known as Senate Bill 4 or S.B. 4, prohibits cities and counties from adopting policies that limit immigration enforcement, allows police officers to question the immigration status of anyone they detain or arrest and threatens officials who violate the law with fines, jail time and removal from office. It also directs local officials to cooperate with so-called immigration detainer requests, which allow foreign-born detainees to be transferred to federal custody after they are released from state or local custody.

A number of the state’s biggest cities, including Houston, Austin, San Antonio and Dallas, all of which are run by Democrats, joined a lawsuit against Texas seeking to strike down the law, which was passed by the Republican-controlled Legislature and signed by the Republican governor, Greg Abbott, in May.