The bill aimed to force local law enforcement to obey requests from immigration officers to hold illegal immigrants for deportation.
Sanctuary cities came under fire from Donald Trump in an executive order during his first week as president.
The Texan law was due to come into effect on Friday.
But on Wednesday, a federal judge ruled it was unlikely to withstand constitutional tests, and prevented implementation of key parts of the bill, called SB4.
In a 94-page decision, US District Judge Orlando Garcia commented: "There is overwhelming evidence by local officials, including local law enforcement, that SB4 will erode public trust and make many communities and neighborhoods less safe."
"There is also ample evidence that localities will suffer adverse economic consequences which, in turn, harm the State of Texas."
He said the court could not "second guess the legislature" but the state could not violate the constitution.
Texas Governor Greg Abbott said the decision made "Texas' communities less safe".
He said he would immediately appeal the decision and was confident the law would eventually be upheld.
Mr Trump's executive order in January covered a range of immigration issues but specifically targeted the 400 or so jurisdictions with policies protecting undocumented immigrants - nicknamed "sanctuary cities".
The presidential order authorised the federal government to withhold funding from cities with such polices.
The Texan bill, passed by the state legislature earlier this year, was set to be one of the first laws of its kind since Mr Trump's order.
A US federal judge has halted a new Texan immigration law on "sanctuary cities" just two days before it is scheduled to go into effect.