The court in Strasbourg on Tuesday threw out the case brought by a Muslim couple in Basel who wanted their two elder daughters, pre-pubescent at the time, to sit out swimming lessons with boys for religious reasons.
In its ruling the court judged that Basel authorities did not violate their right to freedom of religion by insisting their daughters attend the compulsory lessons.
It accepted that the authorities' refusal to exempt the girls interfered with their freedom of religion. But the interference, it said, was justified by the need to protect the children from social exclusion.
School plays "a special role in the process of social integration, particularly where children of foreign origin were concerned," said the court.
Swimming lessons are "not just to learn to swim, but above all to take part in that activity with all the other pupils", it added.
The ruling comes after a long-running battle between the Swiss-Turkish couple and Basel authorities, who back in 2010 fined them 1,400 francs (1,304 euros) after they repeatedly refused to allow their daughters to attend swimming lessons.
The court found that the Basel authorities had tried to accommodate the parents' beliefs by, for instance, allowing the girls to wear the full-body "burkini" swimsuit.
The ECtHR decision backs up an earlier ruling by a court in Basel which said it was important that all children take swimming lessons.
Switzerland’s highest civil court in Lausanne ruled on the case back in 2012, saying the obligation to attend mixed swimming lessons was not an unacceptable attack on religious freedom.
The European Court also judged that the fine of 1,400 francs was fair and proportional “in order to ensure that the parents do send their children to compulsory lessons, which is above all in their own interest, for socialization and successful integration”.
Tuesday's ruling is not final. The couple has three months to appeal the decision.
Swimming lessons are compulsory in schools in Basel and many other places in Switzerland.
Last year authorities in Basel denied two Muslim teens a passport because they refused to participate in swimming lessons and residential camps, saying they were not meeting the requirements of the education system.
Also last year a father in St Gallen was fined 4,000 francs for refusing to send his daughters to school swimming lessons.