Advocates for transgender people in Massachusetts say they can no longer be legally discriminated against in public places.

A new law taking effect on Saturday bars discrimination on the basis of gender identity in public accommodations. Among other things, the statute allows transgender people to use bathrooms and locker rooms that correspond to their gender identity.

The Democratic-controlled Legislature approved the bill after several years of debate. Republican Gov. Charlie Baker signed it into law in July.

Mason Dunn, co-chair of Freedom Massachusetts, a group that advocated for the new law, said Saturday that the protections represent a “shining moment” in Massachusetts’ legacy as an “inclusive, welcoming place.”

The group says Massachusetts is the 18th state to provide similar protections for transgender people.