Transgender students attending public school in Virginia can expect more comprehensive safeguards against harassment from peers, teachers and administrators under a measure signed Wednesday by Gov. Ralph Northam (D).

The legislation, which mirrors policies adopted by roughly a dozen other states, requires the Virginia Department of Education to develop and publish rules regulating the treatment of transgender students in elementary, middle and high schools. The guidelines will span topics including bullying, dress codes, school record-keeping and the use of bathrooms.

The department must finalize and publish its guidance by the end of this year, and school boards throughout the state must adopt the rules by the start of the 2021-2022 school year.

“In Virginia, we fully expect our schools to treat transgender students — like all students — with the dignity and respect they deserve,” Northam said. “This bill represents an important step towards making Virginia more welcoming and inclusive of all.”

The measure, proposed in the House by Del. Marcus B. Simon (D-Fairfax) and Del. Joshua G. Cole (D-Fredericksburg), is the latest in a string of landmark LGBTQ rights measures to pass the General Assembly this year, landing on the governor’s desk with the backing of Democratic majorities in the House and Senate — a level of dominance Democrats have not enjoyed for a generation. The vote on the measure split along party lines in both chambers of the General Assembly.

On Monday, in another victory for LGBTQ advocates, Northam signed a bill banning conversion therapy for minors.

In pushing for the transgender regulations, students, parents and activists argued that a lack of statewide guidance has led to significant variation in how transgender children fare in Virginia schools.

Some students are treated well, allowed to use the bathroom matching their gender identity and to swiftly alter their name and gender as recorded in school documents, such as their high school diploma. But others, families and activists say, are suffering — pain that has sometimes preceded suicide attempts.

Research suggests there are roughly 4,000 transgender teenagers in Virginia, and studies have shown that transgender youth are far more likely to try to take their own lives.

“Kids are at enormous risk,” Robert Norris Rigby, a Virginia high school teacher and president of Fairfax County Public Schools Pride, said in December.

The case of Virginia student Gavin Grimm — a transgender student who was barred by school officials from using the boys’ restroom — received national attention in recent years. Grimm sued, and his suit ascended to the Supreme Court. It was later returned to a lower court, where a judge ruled in August that Grimm’s rights had been violated.

In the years since Grimm’s case, some school districts sought on their own to improve the experience of transgender students: Between 15 and 20 systems, out of more than 130 in Virginia, passed regulations to protect transgender students.

But at least two school systems stipulated that students must use facilities that match their biological sex. Policies such as these seem likely to conflict with the forthcoming Education Department guidelines.

The bill sponsored by Simon and Cole passed the House 60 to 39, with almost every Democrat (one did not vote) and six Republicans in favor. The Senate passed it 22 to 18, with every Democrat and one Republican voting for the measure.

Both chambers also passed an identical Senate bill, proposed by Sen. Jennifer B. Boysko (D-Fairfax), and Northam signed that measure on Wednesday, too.

“Transgender students, their peers and their teachers will benefit from a consistent statewide policy,” Boysko said.

Anthony Belotti, a 19-year-old Richmond college student, found out Thursday morning the legislation had passed when he walked into Cole’s office, where he has been interning part time, and a colleague jumped up to tell him the news.

Belotti, a graduate of Colonial Forge High School in Stafford who identifies as transgender, helped craft the bill in January, offering advice on substance and syntax. It feels surreal, he said, that a piece of legislation he assisted in shaping has become the law of his home state.

“I am so excited that it has passed so that no student will endure what I did,” said Belotti, who developed urinary tract infections after Colonial Forge administrators barred him from using the men’s restroom, causing him to wait until he got home.

He plans to celebrate by gathering with a group of transgender friends — and he will be relishing a few sentences in particular.

“My favorite part of the language in this law,” Belotti said, “is that it allows for districts to add more protections if they feel it’s necessary.”

It feels, he said, like “built-in next steps” leading to a better future.