The European Union’s highest court dismissed complaints on Wednesday 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 divisive dispute that broke out two years ago when more than 1 million migrants poured across the Mediterranean, the European court of justice (ECJ) found that the EU was entitled to order national governments to take in quotas of mainly Syrian refugees relocated from Ita...