Image copyright AP Image caption The governor said Charlotte's ordinance was a "threat to public safety"

The US state of North Carolina has enacted a law that bars its cities and counties from having their own anti-discrimination rules.

Legislators pushed for the bill after Charlotte passed an ordinance allowing transgender people to use restrooms according to gender identity.

A Republican-controlled General Assembly voted on Wednesday to invalidate the ordinance.

The governor, who signed the bill, called it a matter of "basic privacy".

Governor Patrick McCrory said in a release that "the basic expectation of privacy in the most personal of settings" was violated by "government overreach and intrusion" by Charlotte's city council.

Lawmakers several other US states have proposed similar legislation - sometimes referred to as "bathroom bills".

A Houston anti-discrimination ordinance that offered protections for gay and transgender people was overturned by voters in November.

Democrats in North Carolina's Senate walked off their chamber floor in protest as the bill was being debated. It later passed 82-26.

Republican leaders booked the one-day session for $42,000 (£30,000) because the ordinance was set to take place on 1 April.

Local governments cannot prohibit discrimination in public places based on gender identity and sexual preference under the new law.

"We choose not to participate in this farce," said Dan Blue, a Democratic state senator.

Image copyright iStock Image caption Transgender people in North Carolina must use restrooms that match the gender listed on their on their birth certificate

North Carolina Republicans said they felt it was necessary to intervene to protect women and children from Charlotte's "radical" action, arguing that men could enter women's restrooms by calling themselves transgender.

"It's common sense, biological men should not be in women's showers, locker rooms and bathrooms,'' said Republican representative Dean Arp.

Gay rights advocates said the law places a stigma on the transgender community and spreads dubious claims about increased risk of sexual assault. The law will deny the LGBT community basic protections, the groups said.

"McCrory's reckless decision to sign this appalling legislation into law is a direct attack on the rights, well-being and dignity of hundreds of thousands of LGBT North Carolinians and visitors to the state,'' Human Rights Campaign President Chad Griffin said in a statement. "Civil liberties groups pledged to push for repeal and were weighing legal options."

The law requires public schools, government agencies and college campuses bathrooms and locker rooms marked by gender. Transgender people in North Carolina now must use restrooms that match the gender listed on their on their birth certificate .