The European Court of Justice (ECJ) has ruled that Poland, Hungary and the Czech Republic breached their obligations under EU law by refusing to take in refugees.

The ECJ says in its ruling that these countries had failed to accept their share of 120,000 asylum seekers who had arrived in Italy and Greece, under a relocation programme agreed by the European Council in 2015.

It also finds Poland and the Czech Republic guilty of failing to fulfil their obligations under an earlier Council decision with regard to 40,000 migrants. The ruling confirms an opinion by an advisory body to the court last year.

The European Council -- composed largely of national government leaders and heads of state -- adopted their decisions in September 2015 at a time when more than a million migrants had arrived in Europe, most fleeing war in Syria and Iraq.

EU leaders acted to oblige EU countries to help Italy and Greece share the burden due to the disproportionate number to turn up on their shores.

The court, based in Luxembourg, rejected defence arguments put forward by the three member states found to have breached EU law. The ECJ says they have no right to cite maintaining law and/or safeguarding internal security, or claim that the relocation programme was dysfunctional, in refusing to comply.

Under a "temporary relocation mechanism", countries were offered €6,000 per person they took in.

The ECJ says that Poland and the Czech Republic initially agreed to accept 100 and 50 migrants respectively, but failed to do so in practice: the Czechs took in only 12, while Poland accepted none.

Hungary didn't agree to take anyone at all, the court says.

In the end only around 40,000 migrants were relocated. The failure of the burden-sharing measure went to the heart of one of the European Union's major political crises, while immigration became a vote-winning issue for for Europe's far-right parties.

Commenting on the ruling, Varga Judit, Hungary's Justice Minister said that the concept of a 'migrant quota' was "unreasonable from the beginning."

"It was never fully implemented by almost any country," she wrote on Facebook.

"We will continue to fight against the European mainstream, who still did not understand that supporting migration is not a good response to the problems of Europe."

Polish Prime Minister Mateusz Morawiecki said in an interview in 2018 that his government opposed the EU's mandatory relocation scheme for migrants, arguing that Poland still pulled its weight having accepted thousands of refugees from Ukraine.