Judges at the European Court of Justice were asked to decide whether Germany could refuse unemployment benefits to so-called 'poverty migrants' under certain conditions.
Denmark supported the German authorities in the case, which was prompted after a Romanian woman living in Leipzig applied for unemployment benefits and her local job centre refused when she didn't take up jobs they suggested to her.
Both the job centre and a court in Leipzig agreed that 25-year-old Elisabeta Dano, who moved to Germany in 2010 to live with her sister, had never really been looking for work.
But she appealed her case all the way to the European Court.
Now the EU court has said that states must have the right to refuse social benefits to unemployed migrants, a position supported by Denmark.
"We have decided that Denmark should give a submission in the German case because it is of fundamental importance. It goes to the heart of the interpretation of free movement," the then-employment minister Mette Frederiksen told Politiken in March.
The judges wrote that Dano did not have “sufficient means of support“ for herself and her 10-year-old son when she moved to Germany, and therefore couldn't justify her right to remain.
That also meant that she couldn't bring a case against the authorities based on EU anti-discrimination rules.
By agreeing that countries should be allowed to deny immigrants benefits under certain circumstances, the court followed the advice of experts whose testimony it had heard during the case.
They said that it should be legal to deny the applications of people who had travelled to a country with the sole purpose of claiming benefits. This has been the position of the Danish government as well.
"We [support the German case] with the rather simple premise that EU citizens should not travel across national borders to be supported by others. If we travel, we do it to seek a job, to work and to contribute to society," Frederiksen said.
In addition to Denmark, other European Union members have been eagerly awaiting the result, as it will have significant consequences for the current debate on freedom of movement.
British Prime Minister David Cameron hopes to limit the ability of migrants from other EU countries to claim benefits in the UK, as he is faced with a Eurosceptic, anti-immigration challenge from the right by the UK Independence Party.
The court received submissions from Dano's lawyer as well as the German, Danish, Irish, French, Austrian and UK governments and the European Commission, the judges reported in their ruling