The Virginia Senate voted Thursday for a bill to allow private adoption and foster-care agencies to turn away parents for reasons of religious faith or sexual orientation.

Passage of the “conscience clause” bill, by a 22-18 vote, was expected, coming one day after it cleared a close preliminary vote.

It had support Thursday from all 20 Republican senators in the evenly divided chamber as well as two conservative Democrats, Sen. Charles J. Colgan of Prince William and Sen. Phillip P. Puckett of Russell.

The House voted overwhelmingly for its version of the bill last week. Gov. Robert F. McDonnell (R), who has often said that faith-based organizations should be free to set their own policies, is expected to sign the legislation.

Supporters say it would protect the religious freedom of faith-based adoption and foster-care agencies by freeing them from having to place children with parents whose beliefs conflict with their own. Opponents say it perpetuates discrimination against gays and lesbians.

Democrats put up a spirited fight against the bill before its preliminary vote Wednesday, offering no fewer than 18 floor amendments, all of which failed. A handful urged the Senate to vote down the bill before the final vote, saying that it amounted to state-sanctioned discrimination and an endorsement of certain religious views.

“What this bill would do is allow an adoption agency, based on own views, to use state dollars to deny adoption by people who have different religious views,” said Sen. John Edwards (D-Roanoke).

Sen. Jeffrey L. McWaters (R-Virginia Beach), the bill’s patron, said he’d heard all the arguments before in committee.

“Sometimes smart people disagree,” he said.