Switzerland has won a case at the European Court of Human Rights (ECHR) obliging Muslim parents to send their children to mixed swimming lessons.
It said authorities were justified in giving precedence to enforcing "the full school curriculum" and the children's "successful integration" into society.
The ECHR acknowledged that religious freedom was being interfered with.
But judges said it did not amount to a violation.
The case was brought by two Swiss nationals, of Turkish origin, who refused to send their teenage daughters to the compulsory mixed lessons in the city of Basel.
Education officials, however, said that exemptions were available only for girls who had reached the age of puberty - which the girls had not reached at the time.
In 2010, after a long-running dispute, the parents were ordered to pay a combined fine of 1,400 Swiss Francs ($1,380, £1,136) "for acting in breach of their parental duty".
They argued that such treatment was a violation of article nine of the European Convention on Human Rights, which covers the right to freedom of thought, conscience and religion.
In a statement, the ECHR said the refusal to exempt the girls had interfered with the right to freedom of religion.
But it also said the law involved was designed to "protect foreign pupils from any form of social exclusion" and Switzerland was free to design its education system according to its own needs and traditions.
Schools, it said, played an important role in social integration, and exemptions from some lessons are "justified only in very exceptional circumstances".
Swimming, burkinis, and integration
- In 2016, officials in Basel suspended the citizenship process for the family of two teenage Muslim brothers who refused to shake hands with female teachers.
- Switzerland has also applied the law to other cases - a man of Bosnian origin was fined last year for refusing to allow his daughter to take part in swimming lessons during school hours, among other activities.
- Germany also battled with the issue of mixed swimming lessons in 2013, when a judge ruled that a 13-year-old girl must attend - but allowed the wearing of a burkini.
- In France, in 2009, a woman was banned from swimming in a public pool in her burkini. That would be followed in 2016 by a controversial official ban on the garment in public spaces - which was eventually overturned by French courts.
- France, Belgium, and the Netherlands all have bans on Muslim veils in public, to varying degrees.
Read more: The Islamic veil across Europe
"Accordingly, the children's interest in a full education, thus facilitating their successful social integration according to local customs and mores, prevailed over the parents' wish to have their children exempted from mixed swimming lessons," the court said.
The court also noted that "very flexible arrangements" had been offered as a compromise, including allowing the girls to wear burkinis during lessons rather than traditional swimwear, and allowing them to change clothes with no boys in the room.