But when the compromise became public last month, it provoked an uproar from educators and politicians across the ideological spectrum. Justice Minister Simonetta Sommaruga, a social democrat, argued that shaking hands with a teacher was an important part of Swiss culture.

Beat Zemp, the president of the Swiss teachers’ union, also spoke out against the decision, saying that the rules should apply to all students and that it sent the wrong message, since the boys would need to shake hands with colleagues, both male and female, as their lives progressed.

After the backlash, the school decided to refer the issue to the regional authorities.

On Wednesday, the cantonal board for education, culture and sport in Basel-Landschaft said that the integration of foreigners and the fostering of gender equality were in the public interest and that this consideration trumped the private interests of the two students (their names have not been made public).

It acknowledged that forcing the students to shake their female teacher’s hand was an “intrusion” on their religious beliefs but said that it was a proportionate one since, in its view, “it did not involve the central tenets of Islam.”

“In addition, shaking hands was an important social gesture for one’s future career,” it added.

The decision by the Swiss school board comes as Europe is grappling with how to integrate more than a million migrants, many of whom have been arriving from conservative Muslim countries. It also comes amid a simmering culture war in Europe over immigration.