The Republican governor of Texas has signed into law a measure to ban "sanctuary cities" in the state, after months of US President Donald Trump's crackdown on undocumented immigrants.

The law prohibits cities from declaring themselves "sanctuary cities" and enables police officers to check the immigration status of anyone they detain.

The law requires local officials to carry out federal requests to hold criminal suspects for possible deportation and threatens sheriffs with arrest if they refuse to cooperate with federal authorities.

Sanctuary cities limit cooperation with the US federal government's effort to enforce immigration law, with the hopes of reducing deportations so that undocumented people will be more willing to report crimes and enrol their children in schools.

Greg Abbott, the governor, signed the bill on Sunday despite a plea from police chiefs of the state's biggest cities to halt the measure, which they say will hinder their ability to fight crime.

Texas, which has an estimated 1.5 million undocumented immigrants and the longest border with Mexico of any US state, has been at the forefront of the immigration debate.

"As governor, my top priority is public safety, and this bill furthers that objective by keeping dangerous criminals off our streets," Abbott said in a statement.

The law will take effect on September 1.

The Republican-dominated legislature passed the bill on party-line votes and sent the measure to Abbott earlier this month.

It would punish local authorities who do not abide by requests to cooperate with federal immigration agents.

Police officials found to be in violation of the law could face removal from office, fines and up to a year in prison if convicted.

The measure also allows police to ask people about their immigration status during a lawful detention, even for minor infractions like jaywalking.

A tough road

Any anti-sanctuary city measure may face a tough road after a federal judge in April blocked Trump's executive order seeking to withhold funds from local authorities that do not use their resources to advance federal immigration laws.

Democrats have said the measure could lead to unconstitutional racial profiling and civil rights groups have promised to fight the Texas measure in court.

"This legislation is bad for Texas and will make our communities more dangerous for all," the police chiefs of cities, including Houston and Dallas, wrote in an opinion piece in the Dallas Morning News in late April.

READ MORE: Living on the edges in the colonias of Texas

They said immigration was a federal obligation and the law would stretch already meagre resources by turning local police into immigration agents.

The police chiefs said the measure would widen a gap between police and immigrant communities, creating a class of silent victims and eliminating the potential for assistance from immigrants in solving or preventing crimes.

One of the sponsors of the bill, Republican state Representative Charlie Geren, said in a House of Representatives debate the bill would have no effect on immigrants in the country without documentation if they had not committed a crime.

He also said there were no sanctuary cities in Texas at present and the measure would prevent any from emerging.

Bill criticised

The American Civil Liberties Union (ACLU) criticised the bill in a statement.

"This is not the Texas I know," said Terri Burke, executive director of the ACLU of Texas, describing the measure as "racist and wrongheaded".

"Our immigrant communities need to know that we stand with you; we will fight this assault in the courts, at the ballot box, and in the streets, if we have to," Burke said.

"This is an assault on humanity. It will not stand."