North Carolina legislators, in a whirlwind special session on Wednesday, passed a wide-ranging bill barring transgender people from bathrooms and locker rooms that do not match the gender on their birth certificates.

Republicans unanimously supported the bill, while in the Senate, Democrats walked out in protest. “This is a direct affront to equality, civil rights and local autonomy,” the Senate Democratic leader, Dan Blue, said in a statement.

North Carolina’s governor, Pat McCrory, a Republican, signed the bill late Wednesday night.

The session, which was abruptly convened by Republican lawmakers on Tuesday, came in response to an antidiscrimination ordinance approved by the state’s largest city, Charlotte, last month. That ordinance provided protections based on sexual orientation, gender expression and gender identity, including letting transgender people use the public bathrooms that correspond with their gender identity, not gender at birth.

The state bill, put together so quickly that many lawmakers had not seen it before it was introduced Wednesday morning, specifically bars people in North Carolina from using bathrooms that do not match their birth gender, and goes further to prohibit municipalities from creating their own antidiscrimination policies. Instead, it creates a statewide antidiscrimination policy — one that does not mention gay and transgender people. The bill also prohibits local governments from raising minimum wage levels above the state level — something a number of cities in other states have done.