A high court in India's Karnataka state has ruled that the hijab is not "essential" to Islam in a landmark case that could have implications across the country.
The court also upheld a state government order that had banned headscarves in classrooms.
The verdict follows a months-long, divisive row over the hijab.
A Karnataka college's decision in January to bar entry to Muslim girls wearing the hijab had sparked protests.
The issue soon snowballed, forcing the state to shut schools and colleges for several days.
The matter reached the high court after some Muslim women protesters filed petitions arguing that India's constitution guaranteed them the right to wear headscarves.
The court dismissed these pleas, saying that the state government had the right to prescribe uniforms for students.
On Monday, ahead of the verdict, the government restricted large gatherings and shut educational institutions in some areas to prevent protests.
The ruling is likely to be appealed against in the Supreme Court.
"This is a pre-eminently fit case to go before the Supreme Court," Prof Ravi Varma Kumar, a senior advocate who appeared for one of the petitioners, told BBC Hindi.
Thousands of people in India - where Muslims are a minority - had avidly following the court hearings.
A judge who first heard the case had referred it to a larger bench on 9 February, citing the "enormity" of the questions being debated.
The larger bench, while hearing the case, passed a contentious interim order that said students couldn't wear religious clothing - including the hijab - until the court reached a verdict.
This led several Muslim women to skip classes and even their exams while the case was being heard. The row also polarised opinions, with critics seeing it as yet another attempt at marginalising Muslims by Prime Minister Narendra Modi's Hindu nationalist government.
A minister who is part of Mr Modi's government welcomed the order.
"I appeal to everyone that the state and country has to go forward, everyone has to maintain peace by accepting the order of high court," said Prahlad Joshi, federal minister for parliamentary affairs.
The row started in in Karnataka's Udupi district after a government-run college barred six teenage students from wearing the hijab in class.
The college said it allowed students to wear the hijab on campus and only required them to remove it inside the classroom. But the girls, who all wore the mandatory college uniform, started a strike outside the college, arguing that they should be allowed to cover their hair in the classroom.
Udupi is one of three districts in Karnataka's communally sensitive coastal region - a stronghold of Mr Modi's right-wing Bharatiya Janata Party (BJP).
The protests soon spread to other colleges in the state, which is also governed by the BJP. Some Hindu students began going to classes wearing saffron shawls - the colour is seen as a Hindu symbol - which forced officials to insist that both could not be allowed on campus.
The issue attracted international attention after some demonstrations spiralled into violence - Nobel Prize-winner Malala Yousafzai tweeted about the issue, asking India's leaders to do something to "stop the marginalisation of Muslim women".
Source: BBC