The measure codifies a ruling by the Connecticut Commission on Human Rights and Opportunities that made it illegal to discriminate against transgendered people. The bill prohibits discrimination in the workplace or while seeking housing or obtaining credit based on gender identity and expression.

While supporters view the bill as a question of civil rights, critics derided it as “the bathroom bill” and said it could open the door for male predators to gain access to women’s public restrooms by pretending to be transgender.

Republican efforts to amend the bill — exempting restrooms, locker rooms, and boarding houses from the law — failed.

The bill, which passed by a vote of 20-16, has already passed in the state House of Representatives.

Democratic Gov. Dannel P. Malloy has pledged to sign the bill into law.

“This bill is another step forward in the fight for equal rights for all of Connecticut’s citizens, and it’s the right thing to do,’’ the Governor said in a statement following the vote.

“It’s difficult enough for people who are grappling with the issue of their gender identity, and discrimination against them has no place in our society,” said Malloy.