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".