David Cameron has been warned there is no need for fundamental changes to EU immigration rules, after the European court of justice (ECJ) ruled that member states already had the power to stop jobless migrants claiming many benefits for up to five years.

The prime minister welcomed the “commonsense ruling” of the Luxembourg court, but the legal decision could hamper No 10’s efforts to persuade other EU countries they need to change the fundamental principle of free movement.

In a case relating to a Romanian woman living in Germany, the European judgment made it clear that jobless migrants who cannot support themselves and have never worked do not have to be given some non-contributory welfare payments for up to five years after they arrive in a new country.

Cameron described the ruling as “a step in the right direction because, as I’ve said, the right to go and work in another European country should not be an unqualified right. There should be rules about restricting benefits and this is good news”.

The European commission said it was too early to determine how the ruling would affect the UK but said it had always stressed that free movement was a qualified right and not an unconditional one.

Senior Conservative sources said they believed it would give legal backing to a plan to bar jobseekers from the EU from receiving all out-of-work benefits once the universal credit system had been rolled out. . “It is good for the proposal that we’re making with regard to universal credit. It backs up the arguments,” one source said.

But others warned the ruling undermined Cameron’s case for reform of freedom of movement rules. Manfred Weber, head of the centre-right European People’s party (EPP) group in the European parliament, said: “The ruling sends a very strong message because it highlights that member states have many options and legal tools at their disposal to make sure their social system is not abused, without contesting freedom of movement, which is a basic principle of the EU. It sends a clear signal to the member states and to the British prime minister in particular.”

Cameron has promised to seek changes to the fundamental principle on freedom of movement – despite the opposition of the European commission and leading nations including Germany – before offering a referendum by the end of 2017 if he is still in power.

The official German government response to the ruling said: “The right to free movement of persons is a high principle and symbolises the idea behind the EU. But there are limits to the right for equal treatment, which are defined in the European directive on free movement.”

Sophie in’t Veld, first vice-president of the liberal ALDE grouping in the European parliament, said the ruling was a “blow to those suggesting EU free movement rules need to be dramatically curtailed” because it shows countries already have the ability to stop immigrants taking advantage of their welfare systems.

Siôn Simon, Labour’s European spokesman on social affairs, also said it demonstrated that strong powers already existed to prevent a small minority abusing the system. “Both Germany and Belgium are already using such powers. This weak Tory-led government needs to get a grip and do the same,” he said. “Nor is there any evidence for the existence of ‘benefit tourism’ on any widespread scale. It is a Tory-Ukip myth, invented and peddled for the sake of their own political ends, with no regard for the truth or the social fabric of the UK.”

Jonathan Portes, director at the National Institute of Economic and Social Research, said the ruling would affect only a very small number of people, but suggested it could give legal cover to the UK’s existing measures to restrict benefits.

“We can say with confidence that for the most part this establishes that what we were doing anyway is legal. It may have been somewhat dubious before. It might make it easier for us to go further in denying benefits but the number of people [affected] is pretty small as we know this is pretty much a ruling about benefit tourism and that is pretty much a myth.”

Cameron has introduced time restrictions and qualification periods for access to the income-based jobseeker’s allowance. However, he is planning a further crackdown before Christmas in a speech designed to head off the threat of Ukip and allow him to concentrate on the Conservative message on the economy again.

The case was prompted after Elisabeta Dano, 25, a Romanian living in Leipzig, had her application for benefits refused. The local jobcentre argued that there was a lack of evidence to prove that the woman, who has lived in Germany since 2010, had ever actively looked for work.

After an appeal was rejected by a Leipzig court, the case was transferred to the ECJ in Luxembourg. In its ruling, the ECJ emphasised that while EU migrants had the right of residence in another EU country for up to three months, the country was under no obligation to pay social benefits in that period. If migrants stay for more than three months but less than five years, right of residence is dependent on whether they have sufficient resources to support themselves or their family members.