Voters in Switzerland have handed a crushing defeat to a nationalist party's proposal to limit the number of European Union citizens allowed to live and work in their country.

The plan was rejected by 61.7% of voters, compared to 38.3% who were in favour, according to Swiss public broadcaster SRF.

All but four of the country's 26 regions opposed the plan proposed by the Swiss People's Party to give preferential access to jobs, social protection and benefits to people from Switzerland over those from the 27-nation bloc that surrounds it.

The government had warned the measure could further damage the rich Alpine's country's deep and lucrative ties to the EU.

Had it been passed, it would also have triggered reciprocal disadvantages for millions of Swiss citizens if they want to live or work in the EU.

Justice Minister Karin Keller-Sutter welcomed the result, saying: "Especially at this time, during the difficult economic situation caused by the coronavirus crisis, good relations with our neighbours and with the EU are important."

She added that Switzerland would continue to pursue a "bilateral path" with the EU, eschewing membership of the bloc while seeking close economic ties with it.

But she also acknowledged misgivings that many Swiss have about immigration, saying "freedom of movement doesn't just have benefits".

"The Federal Council only wants as much immigration as necessary," Ms Keller-Sutter said. "That continues to be our goal."

Around 1.4 million EU citizens live in the country of about 8.6 million, while around 500,000 Swiss live in EU countries.

Some are dual citizens and would not have been affected by any restrictions.

In a similar referendum in 2014, the Swiss narrowly voted in favour of limiting EU citizens' freedom to live and work in Switzerland.

Politicians refused to fully implement that referendum over fears of a detrimental impact on Swiss society and businesses, prompting the People's Party to put the issue back on the ballot again this year.

Since the last vote, Switzerland has witnessed the fallout from the UK's 2016 Brexit vote, especially for EU citizens in Britain and Britons living on the continent.

One voter in Geneva, Yann Grote, said he did not approve of further limits on freedom of movement. "I'm not at all in favour, and even more now, because it's not a time to isolate Switzerland," he said.

Another voter, Elisabeth Lopes, agreed. "I'm a daughter of immigrants, so it is a matter that touches me," she said.

"If Switzerland had to withdraw or reduce these agreements (with the EU), I think we would be the real losers."

European Commission President Ursula von der Leyen welcomed the result of the referendum, calling it "a positive signal to continue to consolidate and deepen our relationship."

Turnout was higher than in most recent referendums, with almost 60% of voters going to the polls or casting their ballots by mail.