(CNN) A federal court ruled against a Virginia school district on Tuesday, holding that federal law protects a transgender student who sought to use the boys' bathroom at his school.

The ruling is a victory for Gavin Grimm -- a transgender male -- who began his legal fight four years ago and has since graduated from the school. The court denied a motion filed by the school district to dismiss Grimm's lawsuit.

Grimm's lawyers at the American Civil Liberties Union argued that Title IX -- a federal law that prohibits discrimination on the basis of sex in federally funded education programs -- includes discrimination based on gender identity.

"After full consideration of the facts presented and the compelling scope of relevant legal analyses, the Court concludes that Mr. Grimm has sufficiently pled a Title IX claim of sex discrimination under a gender stereotyping theory," wrote Judge Arenda L. Wright Allen, of the US District Court for the Eastern District of Virginia.

A federal appeals court based in Chicago issued a similar ruling in a different challenge in May 2017.

Read More