The Swiss government and most parties opposed the plan to introduce quotas for all types of immigrants, saying it would mean an end to a freedom of movement of people deal agreed with the European Union.
But in a referendum backed by the nationalist People's Party yesterday, 50.5% of voters backed the plan, with about 49.5% against. Approval was strongest in German and Italian-speaking parts of the country, and in rural areas.
Although not part of the EU, Switzerland has negotiated a number of agreements over the years, one of which allowed foreign workers unlimited access to the country.
Switzerland is home to a number of multi-national companies and organisations which employ a workforce drawn from across the globe.
Opponents of the move say it could exacerbate a shortage of skilled workers in Switzerland, the home of Roche, Novartis, UBS, Nestle and other companies filled with foreign professionals.
"Explanatory and constructive talks with the EU are needed urgently," the Swiss Banking Association tweeted after the result.
The outcome means the government will now have to renegotiate painstakingly forged treaties with the EU on the free movement of workers. This could force Switzerland into direct confrontation with EU rules which state freedom of movement is sacrosanct.
The vote also will prove a major headache to bureaucrats in Brussels as it will raise questions about the aspirations of other countries, including the UK, which have growing concerns about unrestricted immigration.
The vote comes amid increasing debate across Europe about migration and the impact of free movement of people.
France's National Front, tipped to come first in the French European elections in May, was quick to congratulate the Swiss voters on their verdict. Similar anti-immigrant parties are doing well in the Netherlands, Austria and Scandinavia.
Switzerland's economy is booming at the moment, and unemployment is low, but many Swiss worry about immigration. One-quarter of the eight million-strong population is foreign, and last year 80,000 new immigrants arrived.
Since 2007, most of the EU's 500 million residents have been on an equal footing with locals in the Swiss job market - the result of a policy voted into law in a 2000 referendum. The outcome of the vote reflects growing concern among the Swiss population that immigrants are eroding the nation's distinctive Alpine culture and contributing to rising rents, crowded transport and more crime.
In a statement, the European Commission said it regretted an "initiative for the introduction of quantitative limits to immigration has been passed by this vote."
The EC spokesman said: "This goes against the principle of free movement of persons between the EU and Switzerland. The EU will examine the implications of this initiative on EU-Swiss relations as a whole. In this context, the Federal Council's position on the result will also be taken into account."