The Hungarian government has failed to achieve a referendum result rejecting EU-imposed quotas on migrant numbers, after an insufficient number of people turned out to vote.

Hungarians overwhelmingly supported the government in a referendum on Sunday called to oppose any mandatory European Union quotas for accepting relocated asylum seekers, but nearly complete official results showed the ballot was invalid due to low voter turnout.

While the government claimed a “sweeping victory”, analysts said the result was an “embarrassing but not totally catastrophic defeat” for Prime Minister Viktor Orban.

With 99.25 per cent of the votes counted, more than 3.2 million voters — or 98.3 per cent of those who cast valid ballots — backed the government. But turnout stood at 43.9 per cent, the National Election Office said. Fifty-percent-plus-one-vote was needed for the referendum to be valid.

About four per cent of the votes were spoiled — twice as many as in any of the other four referenda held since 1997 — driving down the number of valid votes to just below 40 per cent.

The referendum asked: “Do you want the European Union to be able to prescribe the mandatory settlement of non-Hungarian citizens in Hungary even without the consent of Parliament?”

Orban's right-wing, anti-immigrant Fidesz party claimed victory immediately after voting stations closed, saying its own projections based on exit polls showed that 95 per cent of voters supported the government position despite an expected turnout of only 45 per cent.

Vice-chairman of Fidesz, Gergely Gulyas, said: “Today is a sweeping victory for all those who reject the EU's mandatory, unlimited quotas.

“It is a sweeping victory for all those who believe that the foundations of a strong European Union can only be the strong nation states.”

At the same time, analysts said the relentless government campaign against the EU's refugee relocation schemes had oversaturated citizens.

Tamas Boros, an analyst at Policy Solutions, a political research and consultancy firm, said: “Orban was able to dominate public discourse with an issue in which the majority was on his side.

“But it seems he went too far and overestimated how much people's opinions are transformed into votes.”

With a weak opposition in parliament and practically limitless campaign spending to promote the government position, the referendum's lack of validity was considered distressing for the government.

Mr Boros added: “Considering there was hardly any counter-campaign, that they spent some 50 million euros ($56.1 million) and everyone on the right took up the issues wholeheartedly, it's an embarrassing but not totally catastrophic defeat for Mr Orban.

“It is his first national defeat since 2006, the first time in a decade that the prime minister cannot impose his will.”

Mr Orban argued that “No” votes favored Hungary's sovereignty and independence. If a majority of voters agree, Hungary's parliament would pass legislation to advance the referendum's goal whether or not turnout was sufficient for a valid election, he said.

While the referendum has no binding legal consequences for the EU, Mr Orban hoped its passage would increase pressure on Brussels.

He said after casting his own vote: “The most important issue next week is for me to go to Brussels, hold negotiations and try with the help of this result — if the result if appropriate— achieve for it not to be mandatory to take in the kind of people in Hungary we don't want to.”

Mr Orban, who wants individual EU member nations to have more power in the bloc's decision-making process, said he hopes anti-quota referendums would be held in other countries.

He said: “We are proud that we are the first. Unfortunately, we are the only ones in the European Union who managed to have a (referendum) on the migrant issue.”

The invalid result because of the low turnout would make Mr Orban's quest to persuade Brussels to drop the refugee quotas more difficult.

Mr Boros said: “With an invalid result, it is harder for Mr Orban to claim he holds all the aces [against Brussels]. The EU will see that while there is a majority against the quota, it's not the most important issue for Hungarians.”

Separately from the referendum, the Mr Orban government is also suing at the European Court of Justice because of the EU's 2015 decision to relocate 160,000 asylum seekers from overburdened Greece and Italy. Under the original plan, 1,294 asylum seekers would be moved to Hungary.

Polls show that the relentless campaign urging citizens to “send a message to Brussels” while associating migrants with terrorism has increased xenophobia in Hungary.

How Hungary welcomes its refugees - in pictures Show all 15 1 /15 How Hungary welcomes its refugees - in pictures How Hungary welcomes its refugees - in pictures Serbia-Hungary border Refugees protest as Hungarian riot police fires tear gas and water cannon on the Serbian side of the border, near Roszke How Hungary welcomes its refugees - in pictures Serbia-Hungary border A refugee throws a bottle of water towards Hungarian riot police after they used water cannon to push back refugees at the Hungarian border with Serbia near the town of Horgos How Hungary welcomes its refugees - in pictures Serbia-Hungary border Refugees protest as Hungarian riot police fires tear gas and water cannon at the border crossing with Serbia in Roszke How Hungary welcomes its refugees - in pictures Serbia-Hungary border Hungarian armoured personnel carriers are deployed at the border crossing with Serbia in Roszke How Hungary welcomes its refugees - in pictures Serbia-Hungary border Hungarian riot policemen are deployed at the border crossing with Serbia in Roszke How Hungary welcomes its refugees - in pictures Serbia-Hungary border Hungarian police spray water cannon on migrants at the "Horgos 2" border crossing into Hungary, Serbia How Hungary welcomes its refugees - in pictures Serbia-Hungary border A refugee reacts after Hungarian riot police use water cannon to push back refugees at the Hungarian border with Serbia near the town of Horgos How Hungary welcomes its refugees - in pictures Serbia-Hungary border A refugee gestures as Hungarian riot police use water cannon to push back refugees at the Hungarian border with Serbia near the town of Horgos How Hungary welcomes its refugees - in pictures Serbia-Hungary border A refugee throws a stone towards Hungarian riot police after they used water cannon and pepper spray to push back refugees at the Hungarian border with Serbia near the town of Horgos How Hungary welcomes its refugees - in pictures Serbia-Hungary border Refugees protest as Hungarian riot police fires tear gas and water cannon on the Serbian side of the border, near Roszke How Hungary welcomes its refugees - in pictures Serbia-Hungary border Migrants shout slogans as they stand in front of a barrier at the border with Hungary near the village of Horgos, Serbia How Hungary welcomes its refugees - in pictures Serbia-Hungary border Hungarian riot policemen run as they are deployed at the border crossing with Serbia in Roszke Reuters How Hungary welcomes its refugees - in pictures Serbia-Hungary border Hungarian riot policemen are deployed at the border crossing with Serbia in Roszke Reuters How Hungary welcomes its refugees - in pictures Serbia-Hungary border Refugees stand in front of a barrier at the border with Hungary near the village of Horgos, Serbia Reuters How Hungary welcomes its refugees - in pictures Serbia-Hungary border Refugees wait at the Horgos 2 border crossing EPA

Several opposition and civic groups have called on citizens to stay home and boycott the vote. Others urged casting invalid ballots that would not count in the final tally, but still could be interpreted as rejecting the government's “zero migrants” policies.

Nearly 400,000 migrants passed through Hungary last year while making their way toward Western Europe. Razor-wire fences erected on the border with Serbia and Croatia, along with new expulsion policies, have reduced the numbers significantly this year.

Last month, police reported either zero or just one migrant breaching Hungary's border area on 13 different days.

Hungary last year rejected over 80 per cent of the asylum claims made in the country, one of the highest rates in the EU, according to Eurostat, the EU's statistical office. The country granted asylum to 508 refugees, rejected 2,917 applications and had nearly 37,000 claims still being processed.