Relations between Switzerland and the European Union were plunged into confusion last night when the Swiss voted to impose a ceiling on the number of foreign migrants – including citizens of the EU.

Against all expectations, the Swiss narrowly approved a referendum proposal to stop “mass migration”, which will tear up agreements with the EU on free movement of people and goods.

The official result recorded that 50.3 per cent of voters had backed the measure.

Download the new Independent Premium app Sharing the full story, not just the headlines

The proposal, tabled by the right-wing populist UDC (Democratic Union of Centre) party had been fiercely condemned by Swiss business groups and opposed by the federal parliament, President and government.

The result obliges Switzerland to impose unspecified annual ceilings on all foreign migrants, including Britons and other EU citizens and daily cross-border commuters from France, Italy and Germany.

Such limits would breach “open borders” treaties with Brussels, which also allow Swiss goods to circulate freely within Europe and give Swiss businesses the right to bid for EU government contracts.

The Swiss political scientist Pascal Sciarini said the country faced economic “chaos” because all its diplomatic and commercial agreements with the EU would have to be renegotiated from scratch. Over half of Swiss exports go to the EU.

The UDC argued that migration, currently running at 80,000 people a year, threatened to swamp the culture and identity of Switzerland. The country has a population of 8,000,000, of whom one in four were born abroad.

Unless ceilings abolished by a previous referendum in 2000 were re-established, the UDC said, Swiss housing, health, education and transport services would collapse under the pressure from the foreign “invasion”. The “yes” campaign’s posters showed black legs striding purposefully over a Swiss flag – recalling the party’s much criticised poster in a 2009 referendum showing white sheep ejecting a black sheep from Switzerland.

Although the party was again accused of using the race card, the most dramatic effect of the referendum result will be to scramble relations between Switzerland and its neighbours and ethnic cousins in Germany, France and Italy.

Yves Nidegger of the UDC said that a majority of Swiss people had rejected the “alarmist” tactics of business and mainstream parties who had warned that the “ten plagues of Egypt ” would strike the country if it voted “yes”.

Far from taking their revenge by ejecting Switzerland from its EU trade agreements, he said, many European countries would soon follow the “respectable and exemplary” Swiss lead and impose their own curbs on free movement of people within Europe.

Martine Brunschwing-Graf, president of the federal commission against racism, used another biblical image to make the opposite argument. She said that Switzerland had suffered “ten lean years” after it refused to join the EU single market in 1992. Its economy had boomed since it reversed the decision in 2002.

“Now we are throwing away our good fortune,” she said.

Under the Swiss constitution, a referendum needs both a majority of cantons and a simple majority of the popular vote to pass. The proposition “against mass racism” easily won a majority of cantons. The polling institute GfS estimated that the “yes” had won 50.4 per cent of the popular vote – compared to only 43 per cent in favour in the final opinion polls.