The two Eastern European states - backed by neighbour Poland - had argued that the EU's 2015 scheme to have each member state host a certain number of refugees was unlawful.

The programme was designed to help ease pressure on asylum systems in Greece and Italy after mass arrivals across the Mediterranean.

But Yves Bot, the European Court of Justice's Advocate General, rejected most of the procedural arguments presented by Bratislava and Budapest, saying the resettlement scheme was "appropriate for attaining the objective which it pursues".

Europe has been grappling with the worst migration crisis since the end of World War II with an influx of people fleeing the wars in Syria and Iraq while others from Africa are seeking an escape from poverty or political persecution.

Also on Wednesday, the European Commission said it had stepped up its legal case against the Czech Republic, Hungary and Poland over their efforts to block the relocation programme from going into effect.

"Despite repeated calls for action ... these three countries remain in breach of their legal obligations and have shown disregard for their commitments to Greece, Italy and other member states," the EU executive said.

In so-called "reasoned opinions", the Commission has now sent a formal request to these countries to apply EU rules, to which they have one month to respond.

Should the Commission not find the answers satisfactory, it can take the countries to court.