Employers are entitled to ban workers from the "visible wearing of any political, philosophical or religious sign" including headscarves, Europe's top court has ruled.
But the ban must be based on internal company rules requiring all employees to "dress neutrally", said the European Court of Justice (ECJ).
It cannot be based on the wishes of a customer, it said.
It is the court's first decision on the issue of Islamic headscarves at work.
The ECJ's ruling was prompted by the case of a receptionist fired for wearing a headscarf to work at the security company G4S in Belgium.
Belgium's court of cassation had referred the case to the EU's top court for clarification.
The issues of Muslim dress and the integration of immigrant communities has featured prominently in debates in several European countries in recent years.
Austria and the German state of Bavaria have recently announced bans on full-face veils in public spaces.
The rights group Amnesty International said Tuesday's ECJ rulings were "disappointing" and "opened a backdoor to... prejudice".
The Islamic veil across Europe
What's the difference between a hijab, niqab and burka?
The ECJ ruled on the case of Samira Achbita, fired in June 2006 when, after three years of employment, she began wearing a headscarf to work.
She claimed she was being discriminated against on the grounds of her religion.
But at the time of her hiring an "unwritten rule" had been in operation banning overt religious symbols, and the company subsequently went on to include this prohibition explicitly in its workplace regulations, the court explained in its ruling.
That covered "any manifestation of such beliefs without distinction", and was therefore not discriminatory, it said.
'Subjective' banIt said "an employer's desire to project an image of neutrality towards both its public and private sector customers is legitimate" - but national courts must make sure this policy of neutrality had been applied equally to all employees.
It said the Belgian court ruling on the case must also ascertain whether it could have been possible to offer Ms Achbita another post not involving visual contact with customers.
In another case referred to in its ruling, that of design engineer Asma Bougnaoui employed by the Micropole firm in France, the ECJ makes the point that any prohibition on Islamic headscarves must not be based on "subjective considerations".
"The willingness of an employer to take account of the wishes of a customer no longer to have the services of that employer provided by a worker wearing an Islamic headscarf cannot be considered a genuine and determining occupational requirement," it said.
A French court must determine whether the company in this case had dismissed Ms Bougnaoui solely to satisfy a customer or in accordance with a wider internal prohibition on religious symbols, the court ruled.
But John Dalhuisen, director of Amnesty International's Europe and Central Asia programme, said the rulings "give greater leeway to employers to discriminate against women - and men - on the grounds of religious belief.
At a time when identity and appearance has become a political battleground, people need more protection against prejudice, not less.
"The court did say that employers are not at liberty to pander to the prejudices of their clients. But by ruling that company policies can prohibit religious symbols on the grounds of neutrality, they have opened a backdoor to precisely such prejudice."