Workplace bans on the wearing of "any political, philosophical or religious sign" such as headscarves need not constitute direct discrimination, Europe's top court has ruled.
But the ban must be based on internal company rules requiring all employees to "dress neutrally", the European Court of Justice (ECJ) said.
And it cannot be based on the wishes of a customer, it said.
This is the court's first ruling on the wearing of 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.
The issues of Muslim dress and the integration of immigrant communities have 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.
Rights group Amnesty International said Tuesday's ECJ rulings were "disappointing" and "opened a backdoor to ... prejudice".
What is the background to the decision
The ECJ was ruling 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 directly discriminated against on the grounds of her religion and Belgium's Court of Cassation referred the case to the EU's top court for clarification.
At the time of Ms Achbita's hiring, an "unwritten rule" had been in operation banning overt religious symbols, and the company subsequently went on to include this explicitly in its workplace regulations.
Does the ruling affect other religious symbols?
G4S's rules prohibited "any manifestation of such beliefs without distinction", and were therefore not directly discriminatory, the court said.
It said: "an employer's desire to project an image of neutrality towards both its public and private sector customers is legitimate" - but national courts had to make sure this policy of neutrality was applied equally to all employees.
In practice, such a policy must therefore also ban other religious insignia such as crucifixes, skullcaps and turbans, the court told the BBC.
But the court was not absolute in its ruling - workplaces still have a duty to show that they have also not enabled indirect discrimination - whereby people adhering to a particular religion or belief are in practice put at a particular disadvantage, unless that is "objectively justified by a legitimate aim" achieved by means that are "appropriate and necessary".
For instance, the Belgian court ruling on Ms Achbita's case would need to ascertain whether it could have been possible to offer her another post not involving visual contact with customers.
What if a customer complains about a headscarf?
The court ruled that any ban could not be based on "subjective considerations" such as the preferences of an individual customer.
"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," the court said.
It refers to another case in this ruling - that of design engineer Asma Bougnaoui, who lost her job at French firm Micropole, after a customer complained that she wore an Islamic headscarf.
A French court would have to 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 said.
How has this ruling been received?
For years, courts across Europe have faced complex decisions on religious symbols in the workplace.
Jonathan Chamberlain, a partner at UK firm Gowling WLG, said Tuesday's ruling reflected "what has been the UK's approach for some years".
Germany's constitutional court ruled in 2015 a ban on teachers wearing the headscarf across the country's 16 states was unconstitutional. Such a measure was only justified if religious symbols represented a "concrete danger, or the disturbance of school peace".
John Dalhuisen, director of Amnesty International's Europe and Central Asia programme, said the ECJ's decision gave "greater leeway to employers to discriminate against women - and men - on the grounds of religious belief".
"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."
The Conference of European Rabbis said: "With the rise of racially motivated incidents and today's decision, Europe is sending a clear message; its faith communities are no longer welcome."
But the British Humanist Association's Andrew Copson said: "We need to take an approach that balances everyone's rights fairly and we are pleased that the European Court of Justice has today appeared to reinforce that principle."
-BBC