The European Court of Justice (ECJ) has passed a non-binding opinion that confirms that UK government rules restricting EU migrants' access to social security are legal.
The case, brought by the European Commission, concerned the UK's "right to reside" test, which the Commission had described as "discriminatory" and contrary to principles laid down by the EU.
Pedro Cruz Villalón, an ECJ advocate-general, ruled that although the UK indirectly discriminates against EU migrants, this is, "justified by the necessity of protecting the host member state's public finances."
The move has been welcomed by UK MEPs, citing the importance of restricting EU migrant access to certain UK benefits.
This is something David Cameron, UK Prime Minister, is expected to campaign for in his EU renegotiation – specifically his commitment to restricting migrants access to in-work benefits for up to four years following their arrival.
Had the judgement had gone the other way, it would have made Cameron's renegotiation position far more difficult to achieve. It would also provoke a strong reaction from Eurosceptics, who believe national governments should have sovereignty over the EU.
Liberal Democrat MEP, Catherine Bearder, welcomed the ruling saying, "Today's ruling shows that EU citizens do not have an unqualified right to claim benefits in the UK."
She added that, "those Tory Eurosceptics who were hoping to use this as a stick to beat their own Prime Minister will be sorely disappointed."
Anthea McIntyre, Conservative spokesperson on employment in the European Parliament said, "This is very welcome news for Britain's drive to combat benefits tourism."
Referring to Cameron's planned negotiations, she added, "If adopted by the court it bodes very well for David Cameron's renegotiation programme."
The decision is the second case brought before the ECJ in recent months concerning EU migrants' rights to benefits. Last month, the court ruled that unemployed EU migrants could be barred from claiming unemployment benefit, even when they are actively seeking employment.
The case was brought to the European Court of Justice by a Swedish national, Nazifa Alimanovic, against Jobcenter Berlin Neukölln. It had refused to pay Alimanovic benefits as it took the view that as a foreign national living in Germany for economic reasons, she was not entitled to benefits.
McIntyre believes that the ECJ opinion confirms that, "increasingly, the EU institutions and its politicians are starting to realise that member states must be allowed to set their own rules and do things their own way."
She went on, "the ECJ knows which way the political wind blows and it is starting to blow the way of reform in Europe."
The ECJ - the highest court in the EU - will make a final judgement on the case in the coming months. The judgement will be binding on the EU's 28 member states.