The Virginia Senate voted Tuesday to allow religious student groups on college campuses to control who can join their organizations, a move opponents charge would lead to discrimination against gays.

The bill, which passed 22-18 and now moves on to the House, also prevents Virginia universities from penalizing groups that keep their membership exclusive to "only persons committed to the organization's mission."

The bill's chief patron, Sen. Mark Obenshain, a Republican candidate for attorney general, said the bill was aimed at protecting the rights of students to practice their beliefs without the university intervening. He added it didn't just apply to religious groups, but also LGBT or vegan groups that want to restrict membership to people who share similar beliefs.

Obenshain's Republican colleagues -- and at least two Democrats -- backed him up.

"Sometimes the right thing to do is to allow people to be free, express themselves, even when we don't agree with them," said Sen. Tom Garrett, R-Lynchburg.

Democrats said state-supported universities should promote inclusiveness, and not allow groups to bar members based on sexual orientation or any other beliefs.

"I don't think this is just about religion. I think this is about more than that," said Sen. Adam Ebbin, D-Alexandria, the only openly gay lawmaker serving in Richmond. "It's about using taxpayer dollars to fund discrimination."