A federal judge in Virginia sided Tuesday with a transgender teenager who spent most of his high school years fighting to use the boys’ bathroom, ruling that school officials violated his constitutional rights.

Gavin Grimm sued the Gloucester County School Board after it barred him from the boys’ bathroom. The case made Grimm, now a 19-year-old activist in Berkeley, Calif., the face of a national fight for transgender student rights and ascended to the Supreme Court.

The decision comes nearly a year after Grimm graduated from Gloucester High School. But it could provide leverage for other transgender students seeking to use bathrooms that align with their gender identity. It is unclear whether the Gloucester school board will keep the bathroom restrictions on the books. Neither school board members nor their attorney, David Corrigan, responded to requests for comment.

Grimm said he broke down in tears when he received a text message alerting him to the ruling, feeling vindicated — and saddened that it came too late to help him.

“I came to understand a very long time ago that this was not going to affect me in a way that positively impacted my ability to function in school. . . . The issue is for all the kids out there who were waiting for something like this,” said Grimm, who said being forced to use a separate, unisex bathroom contributed to his feelings of alienation at the high school. “The tears were because there was a vindication of what I’ve been saying for four years.”

The decision comes as lawmakers, courts and school principals grapple with how to accommodate students whose gender identity conflicts with the sex on their birth certificates. In recent years, federal judges have delivered a mix of opinions on whether transgender students have the right to use bathrooms corresponding to their gender identity. Some state lawmakers have proposed legislation restricting where transgender people use public restrooms.

U.S. Education Secretary Betsy DeVos and Attorney General Jeff Sessions rolled back protections for transgender students, rescinding an Obama-era directive that called on public schools to allow students to use bathrooms in accordance with their gender identity. The Education Department has stopped investigating civil rights complaints from transgender students fighting for bathroom access, and Tuesday, in response to questions about a similar ruling, DeVos defended the rollback.

“Until the Supreme Court opines or until [Congress] takes action, I’m not going to make up law from the Department of Education,” DeVos said.

Amy Adams, the parent of a transgender girl in middle school in Stafford County, Va., said she hopes the decision will encourage school officials to allow her daughter to use the girls’ bathroom. Now, she is required to use the boys’ bathroom or a staff restroom.

“I’m hopeful that this will be able to turn the tides a little bit in Stafford County,” Adams said.

Judge Arenda L. Wright Allen, who struck down the state’s ban on same-sex marriage in 2014, denied the school board’s request to dismiss Grimm’s case. She ruled the school board violated Grimm’s rights by passing a policy that required students to use bathrooms in accordance with their “biological sex.” The measure was passed in response to parents who were angered when they learned a school principal had allowed Grimm, who began telling people he was transgender as a high school sophomore, to use the boys’ bathroom.

Allen ruled the policy violated Title IX, the federal law that prohibits sex discrimination in public schools, by forcing transgender students to choose between bathrooms where they felt they did not belong and unisex restrooms.

Grimm and other transgender students say that using the bathroom that aligns with their gender identity is critical for their transition. Studies have shown that transgender students are at increased risk for bullying and depression. But conservatives have argued that Title IX does not apply to transgender students and that allowing transgender people in bathrooms that conflict with the sex on their birth certificate violates the privacy of other students.

Grimm was assigned the gender of female at birth but began living life as a boy during his freshman year in high school.

Grimm argued the restriction violated Title IX. The Obama administration backed the student. But Judge Robert G. Doumar in 2015 denied the teen’s request for a court order so he could use the boys’ bathroom.

The U.S. Court of Appeals for the 4th Circuit ruled in Grimm’s favor, deferring to the Obama administration’s argument that bathroom restrictions for transgender students violated Title IX.

Grimm’s case was appealed to the Supreme Court by the school board, and the court was set to hear it in spring 2017.

But the Supreme Court sent Grimm’s case back to a lower federal court after the Trump administration reversed the guidance on transgender student rights.

The judge has asked the school board to schedule a settlement conference with Grimm.

Debbie Truong contributed to this report.