By Robin Emmott and Marton Dunai
BRUSSELS/BUDAPEST (Reuters) - Hungary has broken EU laws on protecting vulnerable migrants and refugees by denying them a right to apply for asylum and forcibly deporting people to the Serbian border, the Court of Justice of the European Union said on Thursday.
Hungary said the ruling was moot as it had already closed the transit zones in concern.
The ruling, which legally requires Hungary to change its policy or potentially face fines, is the latest rejection by EU institutions of Prime Minister Viktor Orban's anti-immigration measures since a migration crisis in 2015.
"The court holds that Hungary has failed to fulfil its obligation to ensure effective access to the procedure for granting international protection," the EU's highest court said in a statement.
It rejected the Hungarian government's position that the migration crisis, when millions of people fled the Middle East and North Africa for Europe, was a justification for breaching EU rules in the name of public order.
During the peak of the crisis, Orban ordered Hungary's southern border to be sealed, blocking a route for hundreds of thousands of migrants and trapping people in so-called migrant transit zones on its borders until May this year.
Orban has built much of his political ideology around a strong anti-immigration stance. He vetoed a 1.85 trillion euro ($2.26 trillion) budget and recovery package for the EU earlier this month because he said it would have forced Hungary to accept migrants it did not want.
Justice Minister Judit Varga said in a Facebook post that the EU court's ruling was "devoid of purpose" with the camps closed. She added Hungary maintained strict border control.
"We will continue to protect the borders of Hungary and Europe and will do everything we can to prevent the formation of international migrant corridors."
"Hungary will only be Hungarian... as long as its borders remain intact. Therefore, not only our thousand-year-old statehood but also the future of our children obliges us to protect our borders."
In a ruling in May, the court said the migrant zones were essentially illegal detention centres, forcing Hungary to close them.
The court also found in Thursday's ruling that Hungary was wrong to forcibly expel non-EU nationals into Serbia, which is not a member of the EU, ignoring EU rules and guarantees.
As it closed the camps, Hungary hardened rules to bar future asylum applicants, contending it borders "safe countries" where they faced no violence so international law did not mandate Budapest to allow them to enter Hungary.
($1 = 0.8174 euros)
(Reporting by Robin Emmott and Marton Dunai; Editing by Frances Kerry)