BOSTON (AP) - The Massachusetts Senate approved a bill Thursday aimed at banning discrimination against transgender people in public accommodations such as restaurants, malls and other locations.

The bill also would let transgender people use bathrooms that correspond with their gender identity. It expands a 2011 state law that already bans discrimination against transgender people in the workplace and housing.

The debate now heads to the Massachusetts House. If the bill becomes law, Massachusetts would join 17 states and the District of Columbia that have banned discrimination against transgender people in public accommodations.

North Carolina has moved in the opposite direction, hastily passing a law in March which limits protections for LGBT people and requires transgender people to use public bathrooms corresponding to the sex on their birth certificate.

The law has been criticized by gay-rights groups, businesses, sports leagues and entertainers, and is now the subject of the dueling lawsuits by the U.S. Justice Department, which wants to scrap the law, and by state officials, who want to keep it in place.

The Massachusetts Senate passed its bill on a 33-4 vote, with four Republican lawmakers opposed.

Democratic state Sen. Sonia Chang-Diaz said it was past time for Massachusetts to act.

“In Massachusetts we are civil rights pioneers by nature, it is in our cultural DNA,” Chang-Diaz said. “That’s why it’s particularly difficult to fathom how it is in 2016 we are still fighting for public accommodations and full equality for transgender Bay Staters.”

Opponents said the bill would violate the privacy rights of women and girls in bathrooms and locker rooms.

Republican Gov. Charlie Baker hasn’t said whether he would sign the bill but indicated a preference for the House version, which includes language intended to discourage and punish false gender identity claims.

Democratic Senate President Stan Rosenberg praised Thursday’s vote.

“As a member of the LGBT community it’s really big for me,” said Rosenberg, who is gay. “This is a fundamental right.”

Transgender activists thanked lawmakers.

“My heart breaks with gratitude. I can’t thank you enough,” Lorelei Erisis, a transgender woman from Ayer, said after the vote. “I’m a writer and I’m losing words. Thank you so much for standing with us and for protecting us.”

Critics argue that male sexual predators could claim to identify as female to gain access to women’s restrooms or locker rooms.

“If this legislation is passed, woman and children will have no protections against being ogled by, or exposed to, naked men,” said Massachusetts Family Institute President Andrew Beckwith.

Supporters of the bill say such fears are unfounded and haven’t been a problem in states that have passed public accommodations laws.

During the debate, senators rejected an amendment that would have created an exemption for gender-based locker rooms and showers where there is an expectation of privacy.

Elizabeth Fournier also opposes the bill. The 18-year-old Seekonk resident said that while the bill tries to reduce the discomfort that transgender individuals might feel by being in a particular bathroom, it merely shifts the discomfort to others.

“In many cases those who will suffer the most from this redistribution of discomfort are women and children,” she said.

The bill includes an emergency preamble, meaning that it would take effect immediately after being signed.