A poster in Geneva from the nationalist Swiss People’s Party demands a stop to immigration to Switzerland. (Anja Niedringhaus/AP)

A tightly contested vote in Switzerland to limit workers from European Union countries brought threats of retaliation Monday from leaders across the continent.

The vote also stoked fears that Swiss citizens were reflecting the zeitgeist across Europe, where right-wing populists increasingly are seizing the spotlight with an anti-immigration political agenda.

Amid claims of an idyllic Swiss lifestyle being trampled by hordes of foreign newcomers, voters narrowly passed a referendum measure Sunday to curb Switzerland’s open-borders treaty with the 28-nation E.U. bloc.

Officials in Brussels, the E.U.’s administrative capital, warned that the vote could threaten Switzerland’s access to the 500 million consumers of the European Union, which stretches from Greece to Ireland and from Latvia to Portugal, and is anchored by economic powers Germany and France.

A famously neutral nation that signed a sweeping treaty with its neighbors in 1999, Switzerland is not a member of the E.U. Yet the fear and loathing over immigration that drove the referendum can also be seen, increasingly, in E.U. countries across the region.

“Switzerland is playing the role of a pioneer for the whole of Europe now,” Toni Brunner, chairman of the Swiss People’s Party — which backed the referendum measure and has launched an initiative to ban mosque minarets — told the Neue Zürcher newspaper. “E.U. open borders, in the form they exist in today, will have to be discussed.”

Hard economic times persist in much of Europe, the legacy of a multiyear debt crisis, leaving immigrants vulnerable to public wrath from Britain to Greece. Hungary’s far-right Jobbik party — anti-immigrant, anti-Roma and anti-Semitic — has moved from the political fringes into the halls of parliament and is campaigning heavily ahead of April elections.

In Athens, the paramilitaries of the Golden Dawn have launched a low-grade street war against immigrants, staging a number of well-documented attacks. The flow of Syrian refugees into Europe has helped boost the popularity of anti-immigrant nationalists in Bulgaria.

Advocates of a more united Europe are bracing for European Parliament elections in May, when anti-immigrant nationalists from France, Holland, Britain, Finland and elsewhere are expected to capture as many as one-third of the seats.

With many far-right European parties adopting protectionist stances, observers note that substantial victories for nationalists could jeopardize European parliamentary approval of a sweeping free-trade accord that is being negotiated with the United States.

“Immigration is the big theme of 2014 in Europe,” said Mats Persson, director of Open Europe, a regional think tank that focuses on E.U. reform. “One of the big risks is that the European Parliament becomes quite polarized after the May elections, filled with federalists who want a closer union in Europe and nationalists who want exactly the opposite.”

Bound by treaties that consider open borders a core value, E.U. member states cannot legally block the flow of citizens from one country to another. But with the citizens of Bulgaria and Romania, two of the region’s poorest nations, recently gaining full mobility rights in the E.U., a host of European leaders are seeking ways to discourage — or block — inter-European immigration.

British Prime Minister David Cameron, a Conservative, is pressing for changes that give individual nations more power to override regionwide laws. Prodded to action by the growing popularity of the anti-immigration United Kingdom Independence Party, Cameron has pledged a referendum by 2017 on whether the fiercely independent island nation should exit the E.U. once and for all.

The British government recently rushed through legislation to restrict benefits for E.U. citizens who move to Britain from elsewhere. Under the new laws, such migrants have to wait three months after arriving before they can apply for unemployment benefits. The government also tightened up the test for migrants seeking benefits. For instance, migrants are now questioned about their English-language skills.

In Berlin, Chancellor Angela Merkel’s government last week appointed a committee to look into ways to curb “benefits tourism,” or the alleged practice of poor Eastern Europeans migrating to Germany for the sole purpose of tapping its generous social benefits.

After the Swiss vote Sunday, the Euro-skeptic party Alternative für Deutschland called for a similar referendum in Germany.

German Finance Minister Wolfgang Schäuble expressed regret Monday over the Swiss vote while acknowledging the tide of fear washing over Europe in connection to immigration.

“People are increasingly uneasy about unlimited freedom of movement in this world of globalization,” Schäuble told ARD, a German public television network.

He and other European officials said the vote in Switzerland will have consequences. The bloc could demand a renegotiation of treaties with Switzerland that allow the free trade of everything from Swiss watches to its trademark cheeses.

Economic retribution, however, appeared to be a risk the Swiss were willing to take.

The Swiss People’s Party sold the referendum measure as a needed step to preserve Swiss identity. Party leaders argued that 80,000 E.U. citizens were setting up shop in the Alps each year, an influx of Italians, Portuguese and other European nationalities that, they said, was changing the social fabric of Swiss cities, villages and towns.

Large Swiss companies argued against the move to set quotas, citing the nation’s very low unemployment rate of 3.5 percent. Switzerland, they said, desperately needs open access to pools of employable talent from nearby countries.

Polls taken several weeks ago suggested that the anti-immigration referendum would fail. But it passed with 50.3 percent support, triggering what are likely to be thorny talks with the E.U. to set caps on foreign immigrants.

“The majority of Swiss have followed a party that repeatedly attracted attention with xenophobic initiatives,” an editorial in the Swiss daily Tages-

Anzeiger said. “Switzerland will have to put its relationship with the E.U. on a completely new basis. All existing and planned agreements will need to be renegotiated.”

Karla Adams in London and Stephanie Kirchner in Berlin contributed to this report.