By Imogen Foulkes
BBC correspondent in Berne
Swiss voters have approved closer ties with the European Union, by agreeing to join the EU's Schengen and Dublin agreements.
The government had pushed for a "Yes" vote
The decision means Switzerland, which is not a member of the EU, will open its borders, and become part of Europe's passport free zone.
The Swiss authorities will also share information with their EU colleagues on crime, and on asylum applications.
The "Yes" vote is a relief for the Swiss government, which wants closer integration with the EU.
In the wake of the French and Dutch rejections of the European constitution, opinion polls in Switzerland had indicated support for the government's position was slipping away.
In the end, the vote was close; 55% said "Yes", 45% said "No".
Swiss President Samuel Schmid said the result was a vindication of the government's policies on Europe.
Foreign Minister Micheline Calmy-Rey, a firm supporter of Swiss membership of the EU, said she was pleased the isolationists had lost.
In fact, the vote reflects Switzerland's complicated relationship with Brussels.
In 1992, the Swiss rejected membership of the European Economic Area, which would have been a first step towards full EU membership. Since then, the EU has been kept firmly at arm's length.
Many Swiss believe EU membership would compromise their country's strict neutrality, and they fear decisions coming from Brussels would undermine Switzerland's system of direct democracy, in which voters have the final say on all major policies.
Karin Gilland-Lutz, a political scientist at the University of Berne, says many people simply fear losing a way of life they regard as superior.
"There is a feeling in Switzerland that there are certain elements of life here which are important, which make Switzerland special - direct democracy and neutrality for example.
"These are both emotionally quite heavily loaded for most people here."
At the same time, many political and business leaders have become concerned about Switzerland's growing isolation.
The EU is Switzerland's most important trading partner, with 60% of Swiss exports going to EU member states.
The Swiss government has negotiated a series of complex bilateral agreements with Brussels, in order to ensure Swiss access to Europe's markets.
However, Brussels will not allow Switzerland to cherry-pick what it regards as the advantages of the EU - trade agreements are dependant on Switzerland signing up to other things, such as the Schengen agreement.
If Schengen and Dublin had been rejected, all the bilateral negotiations would have been at risk. The vote in favour reflects a growing realisation among many Swiss that some sort of deal with the EU is unavoidable.
A majority of Swiss do not want to join the European Union
That does not mean, however, that the Swiss are changing their minds about EU membership.
All the opinion polls show a majority are still against joining.
Furthermore, a substantial minority of voters are against any formal ties at all with the EU.
The right-wing Swiss People's Party forced a referendum on Schengen and Dublin after the government and the parliament had already approved the agreements.
This is a problem that will not go away; every time the government gets an agreement with Brussels, there is a danger that someone will oppose it, and use the much-loved system of direct democracy to force a vote on it.
"This of course may be irritating for Switzerland's negotiating partners," says Karin Gilland-Lutz. "Long negotiations take place, something is agreed, and then ultimately the Swiss government can't go ahead with it.
"It may get to the point where an EU of 25 countries or more just doesn't have the time or energy to negotiate such deals with Switzerland."
The next test for Switzerland's tricky relationship with Brussels with be in September, when the Swiss will vote on extending the agreement on the free movement of labour to the EU's 10 new member states.
This is probably the most controversial of all the bilateral agreements, and Switzerland's anti-EU groups have already begun a high-profile campaign against it.