The Court of Justice of the European Union said on Thursday that Hungary has broken EU laws designed to protect vulnerable migrants and refugees by blocking their right to apply for asylum and forcibly deporting people to the Serbian border.
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 strategy 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.
The court 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.
In an earlier ruling in May, the court said the migrant zones were essentially illegal detention centres, forcing Hungary to close them.
"The Court finds that this system of detention was established outside the cases set out in EU law and without observance of the guarantees which must normally govern it," the court said in reference to its earlier judgement.
The court also found that Hungary was wrong to forcibly expel non-EU nationals using police into Serbia, which is not a member of the EU, without following any EU rules and guarantees that seek to make such deportations more humane.
The court noted that Serbia's land border was "devoid of any infrastructure" and that Hungary did not respect migrants' right to apply for asylum or to remain in the country for a limited period even after their asylum request had been rejected.
While the court's assessment of the case, brought by the European Commission, focuses on the situation in 2017 and early 2018, Hungary has since hardened rules that will effectively bar future asylum applicants. Hungary has argued that it borders so-called safe countries, and so can deport migrants.