A European Court of Justice ruling backing Germany's attempts to restrict unemployed migrants' rights to welfare has been welcomed by David Cameron.
The UK prime minister said the decision on so-called "benefit tourism", which could set a precedent for other EU nations, was "simple common sense".
It could allow the UK to exclude some EU migrants from specific benefits.
Mr Cameron is under pressure to reduce EU migration and will outline his plans by the end of the year.
He has called for reforms to the principle of free movement of people within the EU - but has been told an "arbitrary cap" on numbers will not be accepted.
The BBC's assistant political editor Norman Smith said the government - so often at odds with the European Court of Justice in the past - was hailing the ruling as endorsing Mr Cameron's approach to reforming the EU.
Freedom of movement
But he said the "huge caveat" was that the decision could also be used to show "a big shakeup" of the system was not needed.
The government has already tightened the rules so EU migrants have to wait three months after arriving in the UK before they can claim child benefit and child tax credits.
Migrants are also barred from claiming jobseeker's allowance after three months if they are not looking for work, and the prime minister has said he wants to go further.
He said the European court's ruling was "significant", adding: "It's a good step in the right direction:
"As I've said, the right to live and work in another country should not be an unqualified right; there should be rules about restricting benefits and this is good news."
Work and Pensions Secretary Iain Duncan Smith said the "excellent" ruling backed the government's argument that free movement was not "an absolute right", and backed Britain's cased for tighter curbs on benefits for EU migrants.
Tuesday's ruling from the Luxembourg-based court relates to a case involving a Romanian woman and her son living in Germany who had been denied access to a non-contributory subsistence allowance from its social security system.
Analysis by Europe correspondent Chris Morris
This isn't a blanket ban on EU migrants claiming benefits - nothing like it.
The woman involved in this case, Elisabeta Dano, already receives child benefit in Germany.
But the European Court agreed that she could be denied access to a subsistence allowance available to jobseekers because she isn't actively seeking work.
The Court also said Ms Dano and her son could not claim a right of residence in Germany because they do not have sufficient resources to support themselves.
In response, the European Commission said it has consistently stressed that freedom of movement is about the right of circulation, not about an unrestricted right to claim benefits - and the European Court has confirmed this.
But ironically this ruling could make it more difficult for David Cameron to renegotiate Britain's ability to exclude some EU migrants from parts of the benefit system.
Other EU leaders could turn round and say that the Court has now made it clear that the UK (and others) can already do that under existing rules.
It said the defendant did not have sufficient financial resources to claim residency in Germany after the initial three months and therefore could not claim that the rules excluding her from certain benefits were discriminatory.
More broadly, it said the right of EU citizens to live and work in other member states - the principle of freedom of movement - did not stop states passing legislation of their own excluding migrants from some non-contributory benefits open to their citizens.
National parliaments, it stated, have the "competence to define the extent of the social cover" offered in the form of certain non-contributory benefits.
"The (EU) directive thus seeks to prevent economically inactive European Union citizens from using the host member state's welfare system to fund their means of subsistence," it said in a statement.
"A member state must therefore have the possibility of refusing to grant social benefits to economically inactive European Union citizens who exercise their right to freedom of movement solely in order to obtain another member state's social assistance."
Officials at the Department for Work and Pensions are considering what impact the ruling could have on the UK.
It only applies to non-contributory benefits, where the claimant does not make a contribution through the tax system.
BBC social affairs correspondent Michael Buchanan said calculating the number of EU nationals claiming benefits in the UK was not easy, but according to the government's estimates, they make up 2.5% of all working-age claimants.
More than half are claiming jobseeker's allowance, the benefit most likely to be affected by the ruling, he said, while about 40,000 EU nationals getting sickness and disability benefits could also lose out.
Labour backed the judgement, saying only people who contribute to the economy should be able to fall back on the welfare state.
Shadow work and pensions secretary Rachel Reeves urged ministers to extend the three-month waiting time for benefit claims and stop migrants from claiming child benefit for dependants living abroad.
The European Commission has said it supports action by member states to tackle abuse of the benefits system by migrants but that it will not countenance restrictions on freedom of movement and labour across Europe.