The ruling means that Hungary and Slovakia could face fines if they refuse to abide by the quota system. "The mechanism actually contributes to enabling Greece and Italy to deal with the impact of the 2015 migration crisis and is proportionate." .
The ruling follows an European Union decision made in 2015 to rehouse some 160,000 refugees from Greece and Italy over a period of two years, only around 27,700 of whom have been settled so far.
He said the total to be relocated from the two European Union states is "much lower" with a 97 percent drop in people landing in Greece from Turkey and with the fact most arriving in Italy from Libya are not eligible at all. Hungary and Poland have refused to take part, while Slovakia has only taken in a small number from Greece.
Hungary's Foreign Minister Peter Szijjarto slammed Wednesday's ruling - which is final an can not be appealed - calling it "appalling and irresponsible" and vowed to use all legal means against the judgement, which he said was "the result of a political decision".
Beata Szydlo, the Polish prime minister, said: 'We expected this decision.More news: Turkish President Erdogan talks with Myanmar's Suu Kyi on Rohingya issues
The EU system of migrant resettlement quotas for each country is valid, an EU court ruled today.
The European Commission warned EU member states earlier this year that there were "no more excuses" for not delivering on promises to take on refugees.
The countries claimed the relocation scheme was non-binding as they had voted against the deal, together with the Czech Republic and Romania.
The court added that although pledges by European Union counties to take in asylum seekers are slow - it blamed a "lack of cooperation on the part of certain member states" - the legality of the decision was not affected by the policy's success.
European Home Affairs Commissioner Dimitris Avramopoulos had said he regretted how certain member states "continue to show no solidarity and to ignore our repeated calls to participate in this common effort".More news: Volkswagen introduce scrappage scheme worth up to £6000
The European Commission, the EU executive, welcomed the ECJ ruling.
Fico says the 2015 plan to relocate 160,000 refugees from Greece and Italy over two years was a temporary solution that will cease to be effective on Sept 26.
Hungary and Slovakia were seeking to have the decision annulled. So far only 25,000 refugees have been moved.
To date, Slovakia has accepted only about a dozen.
"Due to the ongoing instability and conflicts in the immediate neighborhood of Italy and Greece, and the repercussions in migratory flows on other member states, it is very likely that a significant and increased pressure will continue to be put on their migration and asylum systems, with a significant proportion of the migrants who may be in need of global protection", the Court of Justice found Wednesday.More news: Trump hints at pulling out of free trade deal with South Korea