People in Switzerland have rejected a plan to automatically expel foreigners who commit minor crimes, results show.
Some 59% of voters have said "No" to the proposal put forward by the right-wing Swiss People's Party.
The vote happened amid growing unease at rising immigration and the problems which, the party says, come with it.
But opponents said the law would create a two-tier justice system unfairly targeting foreigners, who make up around 25% of Switzerland's population.
Almost two million foreign passport holders live permanently and legally in Switzerland, but as gaining Swiss nationality is a complicated and expensive procedure, and is not conferred automatically at birth, these foreign nationals include many who have never lived outside of Switzerland.
The Swiss government says only two in every 100 foreigners living in Switzerland have been granted Swiss citizenship.
Opinion polls initially suggested the proposal would get support, but the mood among voters shifted in the last weeks of the campaign.
More than five million people were entitled to vote in the referendum; only Swiss nationals get to vote.
Analysis: BBC's Imogen Foulkes, in Geneva
This result is a major blow for the right wing Swiss People's Party.
The high turnout, over 60%, and the big majority against the deportation proposal show clearly that voters think the party has gone too far.
The proposal to automatically deport foreigners, many of whom were born in Switzerland, for minor offences such as speeding, was viewed as highly discriminatory.
The size of the defeat over deportation is likely to force the Swiss People's Party to reconsider similar policies, which it has been planning to put to nationwide votes.
In 2010 the Swiss approved measures to deport foreigners convicted of murder or sexual violence.
The proposal rejected on Sunday included automatic deportation with no right of appeal if a foreigner committed two minor offences within 10 years such as speeding or arguing with a police officer.
The changes would have created some of the strictest laws on foreigners in Europe.