A Virginia high school discriminated against a transgender teen by forbidding him from using the boys' restroom, a federal appeals court ruled Tuesday in a case that could have implications for a North Carolina law that critics say discriminates against LGBT people.

The case of Gavin Grimm has been especially closely watched since North Carolina enacted a law last month that bans transgender people from using public restrooms that correspond to their gender identity. That law also bans cities from passing anti-discrimination ordinances, a response to an ordinance recently passed in Charlotte.

In the Virginia case, a three-judge panel of the 4th U.S. Circuit Court of Appeals — which also covers North Carolina — ruled 2-1 to overturn the Gloucester County School Board's policy, saying it violated Title IX, the federal law that prohibits discrimination in schools. A federal judge had previously rejected Grimm's sex discrimination claim, but the court said that judge ignored a U.S. Department of Education regulation that transgender students in public schools must be allowed to use the restroom that corresponds with their gender identity.

"We agree that it has indeed been commonplace and widely accepted to separate public restrooms, locker rooms, and shower facilities on the basis of sex," the court wrote in its opinion. "It is not apparent to us, however, that the truth of these propositions undermines the conclusion we reach regarding the level of deference due to the department's interpretation of its own regulations."

Maxine Eichner, a University of North Carolina law professor who is an expert on sexual orientation and the law, said the ruling — the first of its kind by a federal appeals court — means the provision of North Carolina's law pertaining to restroom use by transgender students in schools that receive federal funds also is invalid.

"The effects of this decision on North Carolina are clear," she said, adding that a judge in that state will have no choice but to apply the appeals court's ruling.

Other states in the 4th Circuit are Maryland, West Virginia and South Carolina. While those states are directly affected by the appeals court's ruling, Eichner said the impact will be broader.

"It is a long and well-considered opinion that sets out the issues," she said. "It will be influential in other circuits."

Appeals court Judge Paul V. Niemeyer, who was appointed to the appeals court by Republican President George H.W. Bush, wrote in a dissenting opinion that the majority's opinion "completely tramples on all universally accepted protections of privacy and safety that are based on the anatomical differences between the sexes."

The majority opinion was written by Judge Henry F. Floyd and joined by Judge Andre M. Davis, both appointees of Democratic President Barack Obama. The Richmond-based court was long considered the nation's most conservative federal appeals court, but a series of vacancies in the last few years has allowed Obama to reshape it. Including the two senior judges, the court now has 10 judges appointed by Democrats and seven by Republicans.

The school board could appeal the decision to the full appeals court or the U.S. Supreme Court. David Patrick Corrigan, attorney for the school board, did not immediately respond to a telephone message.

On another issue, the appeals court ordered the trial judge to reconsider his refusal to issue an order that would allow Grimm to use the boys' restrooms immediately.

Grimm was born female but identifies as male. He was allowed to use the boys' restrooms at the school for several weeks in 2014. But after some parents complained, the school board adopted a policy requiring students to use either the restroom that corresponds with their biological gender or a private, single-stall restroom.

Grimm called the policy stigmatizing. School officials said the policy respects the privacy of all students.

"I feel so relieved and vindicated by the court's ruling," Grimm said in a statement released by the American Civil Liberties Union, which represents him. "Today's decision gives me hope that my fight will help other kids avoid discriminatory treatment at school."

Grimm, 16, said he started refusing to wear girls' clothes by age 6 and told his parents he was transgender in April 2014.

Grimm's parents helped him legally change his name, and a psychologist diagnosed him with gender dysphoria, characterized by stress stemming from conflict between one's gender identity and assigned sex at birth. Grimm began hormone treatment to deepen his voice and give him a more masculine appearance.