The European Union's highest court has dismissed complaints by Slovakia and Hungary about EU migration policy, upholding Brussels' right to force member states to take in asylum seekers.

In the latest twist to a dispute that broke out two years ago when more than one million migrants poured across the Mediterranean, the European Court of Justice found that the EU was entitled to order national governments to take in quotas of mainly Syrian refugees relocated from Italy and Greece.

"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, adding it rejected the complaints "in their entirety".

"The mechanism actually contributes to enabling Greece and Italy to deal with the impact of the 2015 migration crisis and is proportionate."

The programme set up by the executive European Commission was approved by majority vote of member states in the face of opposition from formerly communist countries in the east who said their societies could not absorb mainly Muslim immigrants.

It provided for the relocation of up to 120,000 people, but only about 25,000 have so far been moved.

A further programme for resettling people directly from outside the EU has also struggled to hit targets for taking in asylum-seekers.

Migration Commissioner Dimitris Avramopoulos tweeted: "Time to work in unity and implement solidarity in full."

The Commission's chief spokesman, however, denied a report that the executive would propose a new round of 40,000 relocations.

It is unclear how far Brussels may try to force eastern states to take refugees, many of whom themselves are reluctant to settle in the poorer, ex-Soviet bloc.

However, countries like Germany and Italy which are housing large numbers have said the easterners are jeopardising western-funded EU subsidies if they go on refusing, adding to deep strains in the bloc as it deals with Britain's imminent exit and a still limping economy.

"The quota system does not work, so the court decision is, perhaps, irrelevant at the moment," Slovakia’s Economy Minister Peter Ziga told reporters.

He said a new mechanism was needed though the problem was not as grave as arrivals had declined.

"I think the European Commission will find a way to solve this problem," Mr Ziga added.

Eastern leaders say the bloc should control its borders better to crack down on illegal immigration – something Brussels says it has succeeded in doing in the past two years.

The EU has taken in more than 1.7 million people from the Middle East and Africa since 2014. But, after a mass influx in 2015, numbers have gone down steadily following actions last year that all but closed the route from Turkey to Greece and from Greece to the Balkans and northern Europe.

The EU has also increased support for Libya to curb arrivals in Italy.

The eastern EU states say they can send equipment and border guards to the bloc's external frontiers in solidarity.

Hungary and Poland have refused to host a single person under the 2015 sharing scheme, while Slovakia and the Czech Republic have each taken in only a dozen or so.

Hungary and Slovakia react strongly to ruling

Following the decision, Slovakian Prime Minister Robert Fico said he respects the decision but said his country's position on refugee quotas will not change.

"We will continue to work on having solidarity expressed in different ways other than forcing (on us) migrants from other countries that don't want to be here anyway," he said.

Hungary's Foreign Minister reacted to the ruling in a stronger fashion, describing it as appalling.

"The Hungarian government considers today's decision by the European court to be appalling and irresponsible," Peter Szijjarto told a news conference.

"This decision jeopardises the security and future of all of Europe."

Mr Szijjarto said the decision was ma de based on political rather than legal or professional considerations.

Meanwhile, Polish Prime Minister Beata Szydlo has said that Poland will continue to refuse to accept migrants under the EU relocation scheme despite the ruling.

Speaking to reporters, Ms Szydlo said: "I was convinced that such a decision would be made (by the court), but this absolutely does not change the stance of the Polish government with respect to migration policy."