The European Union’s top court ruled Wednesday that member states can be forced to take in asylum seekers, rejecting challenges by Hungary and Slovakia to stay out of the system the EU began two years ago.

The European Council approved the resettlement plan over the objection of some eastern European nations. The system was meant to relocate 160,000 refugees who have fled to Greece and Italy in order to help prevent those countries from being overwhelmed. So far only about 24,000 people have been resettled.

The European Court of Justice said Wednesday that the council was not required to unanimously approve the plan and had the authority to “respond effectively and swiftly to an emergency situation.”

Hungary and Poland have refused to accept any of the refugees, while Slovakia has taken in only a few.

Hungary’s prime minister, Peter Szijjarto, said after the ruling Wednesday that his government finds the decision “appalling and irresponsible.” He said it jeopardizes the security and future of Europe.

Slovakian Prime Minister Robert Fico told reporters his country will respect the court’s decision, but its position objecting to the quotas has not changed.