A bill allowing prayer in Virginia schools has passed the state Senate by a vote of 20 to 18, largely along party lines.

The legislation, introduced by three conservative Republicans, would codify students’ right to pray before, during and after school; organize prayer groups, clubs and events; wear religious clothing or accessories; and express religious viewpoints at school forums. Advocates said the issue is one of free speech.

“I don’t think there’s anything in this bill that would prevent a Hindu, a Muslim, a Jewish, a Christian or indeed a nonreligious student from exercising their rights under the bill,” Sen. Richard H. Black (R-Loudoun) said.

Democratic opponents argued that if the bill passed, members of minority faiths would be forced to endure Christian proselytizing. “Prayers are unlikely to be from anything but the majority religion,” said Sen. Adam P. Ebbin (D-Alexandria). Sen. John S. Edwards (D-Roanoke) warned that the bill “almost guarantees litigation.”

One Republican, Sen. John C. Watkins (Chesterfield ), voted against the bill. One Democrat, Sen. Phillip P. Puckett (Russell), voted for it. In previous years, conservatives have pushed for an amendment to the state constitution protecting prayer in schools.

Gov. Terry McAuliffe (D) has not taken a position on the bill, which will probably pass in the Republican-dominated House of Delegates.