Del. Kathleen J. Murphy (D-Fairfax) confers with Del. C. Todd Gilbert (R-Shenandoah) during the floor session of the House of Delegates at the State Capitol in Richmond on Tuesday. (Bob Brown/Richmond Times-Dispatch via AP)

A House panel on Thursday advanced a bill that — because of a last-minute addition — would allow any person or organization to discriminate against someone for having extramarital sex.

The bill would also prohibit state agencies from punishing discrimination against people who are transgender or who are in same-sex marriages. The provision about sex outside of marriage was added minutes before lawmakers voted.

The legislation advanced 13 to 7 in the GOP-controlled committee, with members voting along party lines, except Del. Joseph R. Yost (R-Giles), who voted no. It is headed for likely passage by the full House next week. Gov. Terry McAuliffe (D) has said he would veto the bill if it reaches his desk.

Supporters — including the bill’s sponsor, Del. C. Todd Gilbert (R-Shenandoah) — say the measure anticipates that people with religious convictions could be punished for those beliefs as acceptance of lesbian, gay, bisexual and transgender individuals becomes the norm across the United States. Donors to nonprofit organizations such as Catholic Charities worry that their contributions may no longer be tax-deductible or that a religious charity could lose a government grant, Gilbert said.

The provision protecting those who believe “sexual relations are properly reserved to” a marriage between one man and one woman was added at the request of the Family Foundation of Virginia, which helped draft the bill.

Opponents call the bill a “dangerously broad” license to discriminate that goes beyond high-profile cases of bakers who don’t want to make cakes for gay weddings. For example, the bill could block the state from pulling funding from religious schools that deny admission to children of gay parents or prevent a city from revoking a license from a hotel that won’t accept unmarried guests, they say.

“Our General Assembly ‘in its wisdom’ has passed unconstitutional legislation on more than one occasion in the past, but I don’t recall one that was this obviously unconstitutional in a long time,” said Claire Guthrie Gastañaga, executive director of the American Civil Liberties Union of Virginia.

In the run-up to the March 1 presidential primary in Virginia, observers say Republicans want to send a message to conservative voters who will choose the GOP nominee, while Democrats have seized on the bill as a way to cast Republicans as out of step with mainstream society.

The bill is among many that have cropped up across the country since the Supreme Court affirmed the right of gay couples to marry in all 50 states last summer.

Virginia’s legislation was filed by Gilbert, the House deputy majority leader, after Speaker William J. Howell (R-Stafford) asked him to review what other states had done to protect what they call religious freedom.

Gilbert said the bill is in keeping with “an age-old approach to public policy” in the tradition of Thomas Jefferson.

“I think people of faith feel the tide turning so strongly that all they’re looking for is some reasonable accommodation, because they view that there is this secular church, if you will, that’s trying to impose its belief system upon every­body else,” he said. “As in, ‘You agree with all this or else.’ ”

The nonprofit group Equality Virginia, however, said the bill “doubles down on discrimination” because it is already legal in Virginia to discriminate against gay and transgender people in the workplace, housing and public accommodation.

“We don’t allow people to discriminate against . . . interracial marriages, interfaith marriages, disparate-age marriages. We can’t start this precedent where there’s this one type of relationship that people can discriminate against without any fear of punishment,” said James Parrish, executive director of Equality Virginia.

In response, Chris Freund, spokesman for the Family Foundation of Virginia, noted the bill is similar to one already on the books that says faith-based adoption agencies do not have to serve same-sex couples.

“We’ve always tried to find accommodation for religious beliefs when there’s a conflict between existing rights,” he said. “The goal of this is to provide that accommodation. I would argue that simply following your faith belief about human sexuality is not discriminatory.”

Under the bill, people with religious beliefs — including an individual, corporation, partnership, association, trust, society or any other legal or commercial entity — could discriminate against gay couples, transgender people or unmarried couples without fear of losing tax benefits, grants, contracts, loans, scholarships, certification, accreditation or jobs.

There are exceptions for hospitals making decisions about visitation or emergency medical treatment.

In separate action, the Senate on Friday passed a bill that its Republican sponsor said would ensure that members of the clergy could not face criminal or civil penalties for refusing to marry gay couples.

Democrats said they had no desire to force any members of the clergy to perform any marriage ceremonies if they oppose the unions on religious grounds. But they said that as written, the Senate measure could allow religious organizations that engage in commerce, such as renting out banquet halls to the general public, to turn away gay couples. After a heated debate, the measure passed on a 20-to-19 ­party-line vote, with one member, Sen. Jill Holtzman Vogel (R-Fauquier) absent for the day.

Laura Vozzella contributed to this report.