BRUSSELS - The EU on Wednesday won a legal battle against eastern European countries that rejected a quota scheme to force member states to admit tens of thousands of asylum seekers.

The European Court of Justice, the 28-nation bloc’s top court, threw out the challenge from Hungary and Slovakia against a scheme Brussels launched two years ago to ease the burden on overstretched Greece and Italy.

Europe has been grappling with the worst migrant crisis since World War II, with hundreds of thousands of people fleeing war, persecution and poverty in the Middle East and Africa. “The court dismisses the actions brought by Slovakia and Hungary against the provisional mechanism for the mandatory relocation of asylum seekers,” the Luxembourg-based court said. “That mechanism actually contributes to enabling Greece and Italy to deal with the impact of the 2015 migration crisis and is proportionate.”

The continuing crisis peaked in 2015. More than 1.6 million people have landed on Greek and Italian shores since 2014.

The verdict was welcomed by the European Commission, the executive of the 28-nation bloc.

“ECJ confirms relocation scheme valid. Time to work in unity and implement solidarity in full,” said EU Migration Commissioner Dimitris Avramopoulos.

However, Hungarian Foreign Minister Peter Szijjarto slamed the verdict as “irresponsible,” saying it “threatens the security of all of Europe”. Hungarian Prime Minister Viktor Orban has called migration the “Trojan Horse of terrorism.”

The top court’s press office told AFP there is “no onward appeal for Hungary and Slovakia” when asked about Szijjarto’s comment that Budapest will use “all legal means” against the scheme.

In its verdict, the court upheld the right of EU institutions to respond “swiftly to an emergency situation” over the massive migrant influx.

It also held that the European Council, the body of member states, “was not required to act unanimously when it adopted the contested decision”.

A majority of EU member states decided in September 2015 to relocate 120,000 Syrian and other asylum seekers from overstretched Greece and Italy to most of the other 28 EU member states. It is part of a scheme to relocate a total of 160,000 asylum seekers.

Officials in Brussels have argued that the scheme is legally binding on member states, including those that voted against the quotas like Hungary, Slovakia, the Czech Republic and Romania.

Poland initially supported the plan but has come out strongly opposed since a right-wing government came to power.

The court statement said Poland intervened in support of Hungary during the proceedings, while the European Commission, along with Greece, Italy, Germany, Sweden and several other member states, argued for the relocation plan.

Eastern European member states opposed the plan, saying they were not equipped to integrate people from mainly Muslim countries.

Brussels launched the relocation scheme in September 2015, the year more than one million migrants arrived in Europe by sea.

It was introduced as an exception to the so-called Dublin rules under which migrants must apply for asylum in the member state where they first land.

Under international and European law, countries are required to grant asylum to people fleeing war or persecution but not those classed as economic migrants.

Political pressures have eased with a sharp decline in migrant flows.

This is mainly a result of a controversial deal the EU signed with Turkey in March last year to send back migrants in return for billions of euros in aid and for admitting asylum seekers directly from refugee camps in Turkey. However, the scheme has faced trouble from the start.

EU figures show that just under 28,000 people have been relocated since the two-year scheme was launched in September 2015. In addition to outright opposition from eastern member states, other EU member states have dragged their feet despite having voted for the plan.

Under the plan, Hungary must admit more than 2,300 asylum seekers, while Slovakia must in the long term take in 1,400.