The 12-year-old, originally from Morocco but going to school in the southern German city of Frankfurt, had refused to take part in swimming lessons and had been marked down accordingly.
She filed to be given the right to skip the classes, her lawyer arguing that according to the Quran, she was not only forbidden from showing herself to boys but also from seeing the topless boys.
An administrative court in Kassel, western Germany, rejected her application.
It said in its ruling that she could wear the full-body swimsuit, known as the “burkini” already used by several girls at her school, which would be enough to guarantee her religious freedom.
The family had chosen to live in Germany where mixed swimming classes were the norm, the court pointed out.
One of the aims of the school system was to promote integration and tolerance, the court added, citing a ruling by Germany’s constitutional court.
The applicant would have to put up with the sight of her classmates in their swimming costumes, the court said.