SAN ANTONIO (Reuters) - A small border town and some of the largest cities in Texas told a federal judge on Monday a new state law aimed at punishing sanctuary cities could lead to an immigration police state and asked him to halt it because it was unconstitutional.

Slideshow ( 3 images )

The Republican-backed law in Texas, the U.S. state with the longest border with Mexico, takes effect on September 1. It is the first of its kind since Republican Donald Trump became president in January, promising to crack down on illegal immigration.

The law, known as Senate Bill 4, calls for jail for police chiefs, sheriffs and possibly frontline officers who fail to cooperate over U.S. immigration. The measure also allows police to ask about immigration status during a lawful detention.

A lawyer for Texas said the law helps ensure conformity across the state on the application of immigration law and prevents localities from adopting positions of non-cooperation with federal authorities.

“It is a moderate law that fits hand in glove with federal immigration policies,” Darren McCarty, an attorney for the state, said in opening statements.

But Lee Gelernt, an attorney for the American Civil Liberties Union who represents the plaintiffs, said if the court upholds the Texas law it could have national ramifications.

“That would set up an immigration police state,” he told U.S. District Judge Orlando Garcia.

“We could be removed from office if we endorse a policy that is different from the law,” Austin Mayor Steve Adler said outside court, adding that the law violates constitutional free speech protections.

Other cities that sued to block the law include Austin, Dallas, Houston and San Antonio.

Plaintiffs also contended the law could lead to racial profiling and divert resources from local police who would be under the threat of job loss and fines if they do not cooperate with federal immigration authorities.

Several hundred protesters rallied against the law outside the court. A decision in the case was not likely to come soon.

SB 4 supporters have said immigrants who do not break the law have nothing to fear. Critics contend SB 4 allows police to detain people for up to 48 hours for immigration checks, even for minor infractions such as jaywalking.

On Friday the Trump administration filed court papers to support the Texas law, saying it will help keep America safe. A U.S. Department of Justice lawyer told the court on Monday the Texas law will ensure co-operation on immigration matters.