Three girls in North Carolina were fed up with a school policy prohibiting female students from wearing pants. Skirts, they said, were uncomfortable and restrictive. They wanted to be free to play at recess, do cartwheels with the boys and focus on learning in the classroom — not the position of their legs.

So the girls, then ages 5, 10 and 14, decided to do something about it.

What began with a school petition by one of the students seeking to allow girls to wear pants to school stretched into a yearslong battle that culminated last week when a federal judge struck down the school’s uniform policy as unconstitutional.

“The skirts requirement causes the girls to suffer a burden the boys do not, simply because they are female,” the judge, Malcolm J. Howard, wrote in the ruling, filed on Thursday.

The ruling landed amid a larger discussion about how female students of all ages are viewed, after recent episodes at other schools.