A federal judge in Oregon issued a ruling this week in favor of transgender students, saying that forcing them to use restrooms that correspond with the gender they were assigned at birth would violate civil rights law.

In a 56-page opinion released Tuesday, Judge Marco A. Hernández of Federal District Court in Portland said that transgender students should be allowed to use bathrooms that match the gender they identify with. The ruling upheld the policy of a school district in Dallas, Ore., that allowed a male transgender student to use the boys’ restrooms, showers and locker rooms.

The judge dismissed claims by some students and parents saying that other male students experienced “embarrassment, humiliation, anxiety, intimidation, fear, apprehension and stress produced by using the restroom with students of the opposite sex.”

Judge Hernández wrote in his opinion, “Forcing transgender students to use facilities inconsistent with their gender identity would undoubtedly harm those students and prevent them from equally accessing educational opportunities and resources.”