The European Union won an important victory on Wednesday in its fractured effort to deal with the huge wave of migration that began in 2015, as the bloc’s top court ruled that Hungary and Slovakia were obligated to accept migrants under a contentious quota system.
A summary of the judgment said the Court of Justice had dismissed “in their entirety the actions brought by Slovakia and Hungary.” The quota program was “necessary to respond effectively and swiftly to an emergency situation characterized by a sudden inflow of displaced persons,” the court said.
The case has highlighted a deep divide in the European Union as it sought a joint solution to dealing with the more than one million people who have come to Europe in the past two years, straining resources, roiling politics and drawing criticism from rights advocates who say that the bloc risks violating international laws on the treatment of refugees.
Many member states were lukewarm toward the quota plan from the start, but Hungary and Slovakia stood out by openly spurning their quota requirements and trying to overturn them. A looming question is whether the European Commission, the bloc’s administrative arm, will renew the relocation program.
“Given the tense politics of internal solidarity, it might make more sense for the commission to avoid insisting on the commitment, having made its point,” said Elizabeth Collett, the European director of the Migration Policy Institute, a research organization. “Few E.U. member states have actually met their relocation quota, and most were just a lot more passive about it.”
The 2015 program to relocate migrants traveling through Greece and Italy to other countries was put into place as the migration crisis from Africa, the Middle East and elsewhere reached its peak, but only about a third of nearly 100,000 places have been filled.
Huge numbers of migrants arriving in Greece and Italy have made journeys to countries like Germany and Sweden; arrivals have slowed since the program’s inception, and not all migrants in Greece and Italy qualify for relocation.
More than one million migrants have applied for asylum in Germany, and the country’s foreign minister, Sigmar Gabriel, welcomed the ruling on Wednesday as “explicitly clear,” emphasizing that all European Union members would now be expected to accept their quota of refugees.
“I have always told our Eastern European partners that it is correct to put questions to the courts,” Mr. Gabriel said. “But now we can also expect that all European partners will uphold the ruling and the carry out the decision without further delay.”
Hungary could be ordered to pay fines if it fails to take in its quota of 1,294 people, though enforcement might require the European Commission to bring its own court case.
Poland and the Czech Republic may face similar legal action, but Slovakia has accepted a small number of migrants relocated from Greece and has recently shown a greater willingness to find common ground with Brussels.
Peter Szijjarto, the Hungarian minister of foreign affairs and trade, called the ruling “outrageous and irresponsible” and said “the real battle is only just beginning,” insisting that no one would be relocated to Hungary against its wishes.
The quota system was introduced as part of an effort to relieve the burden on Greece and Italy, where migrants — many of them fleeing the war in Syria — reached the European Union in huge numbers in 2015 and 2016. But the bloc soon faced intense opposition from member states in Central and Eastern Europe that resented any obligation to accept a preset number of migrants arriving in Greece and Italy.
The program formally ends Sept. 26, but migrants arriving in European Union states until that date can qualify. According to estimates by European officials, about 22,000 people who have arrived, or who are expected to arrive in Greece and Italy before the September deadline, could be eligible for relocation. But only about half of them are likely to qualify for relocation to another member state, where then they could apply for asylum, officials said.
Ms. Collett said Europe’s leaders were increasingly focused on an effort to stop migrants from trying to get to Europe in the first place. That entailed closer “relationships with key third countries like Niger and Libya, or simply providing cash to encourage governments to limit flows,” she said, referring to funding for programs like job creation and for security measures to keep migrants from attempting the hazardous trip to Europe.
Elements of that approach have enraged Oxfam, a charity that warned the European Union last month that migration policies preventing people from leaving Libya exposed them to torture, rape and slavery.
In March 2016, the European Union reached a deal with Turkey to send back asylum seekers who had taken clandestine routes to Greece from Turkey. That measure, including payments of up to 6 billion euros, or $7.1 billion, to help Turkey manage its refugee population and a pledge to reinvigorate talks on the possibility of Turkey joining the bloc, slowed the flow across the Aegean route to a trickle.
That deal is looking increasingly tenuous, and Chancellor Angela Merkel of Germany called last weekend for an end to negotiations with Turkey, infuriating Ankara. Since the original agreement with Turkey, the focus has been on the so-called Central Mediterranean route used by many migrants to travel from Libya to Italy.
According to the International Organization for Migration, 125,860 migrants and refugees have arrived in Europe by sea so far this year. Nearly 80 percent arrived in Italy, with the rest divided among Cyprus, Greece and Spain. More than 2,500 people have died trying to cross the Mediterranean, the group said.
That number of arrivals is less than half the number registered in the same period last year, when 3,238 died at sea.