(CNN) The European Court of Justice (ECJ) has rejected a challenge brought by Hungary and Slovakia against the European Union's power to force member states to admit asylum seekers.

The two nations opposed a 2015 decision by the EU's top policy body, at the height of the Mediterranean migration crisis, to assist Italy and Greece by making other EU states admit 120,000 people.

"That mechanism actually contributes to enabling Greece and Italy to deal with the impact of the 2015 migration crisis and is proportionate," a news release on the ECJ's ruling said.

The court "dismisses in their entirety the actions brought by Slovakia and Hungary," it said.

Hungary and Slovakia, along with the Czech Republic and Romania, had opposed the 2015 decision, taken by the Council of the European Union. The formerly Communist nations in eastern Europe claimed they would struggle to absorb mainly Muslim refugees from Syria.

Read More