Image caption There are concerns the UK could be forced to pay out to so-called "benefits tourists"

The European Commission has threatened legal action against the UK, saying a test of eligibility for benefits discriminates against foreigners.

It says it is easier for UK citizens to prove their "right to reside" - a test imposed by the UK for certain benefits - than EU nationals.

The commission says it may refer the case to the European Court of Justice.

Ministers say it is a "fundamental challenge" to the UK's right to decide its own social security arrangements.

The Commission says it has been in talks with the UK for several years over the issue and is responding to a "huge number" of complaints from EU citizens living in the UK.

Residence tests

On Thursday it announced that it was giving the UK two months to explain how it was going to bring its legislation into line with EU law - prompting UK Work and Pensions Secretary Iain Duncan Smith to accuse it of a "land grab" and to pledge to fight it.

A range of entitlements - including child benefit, child tax credit, state pension credit, jobseekers' allowance and employment and support allowance - are given only to those with a "right to reside" in the UK.

WHAT BENEFITS ARE INVOLVED Child benefit

Child tax credit

State pension credit

Jobseekers' allowance

The Commission says there are already an EU-wide "habitual residence" rules which are strict enough and the UK is imposing an additional test, which indirectly discriminates against non-UK EU nationals.

While UK nationals can easily prove their "right to reside" based on their UK citizenship, other EU nationals have their applications heard on a case-by-case basis, which it says breaches EU social security co-ordination rules giving all citizens equal rights.

The Commission gives the example of a woman who moved to the UK and worked from April 2007 to April 2009 when she was made redundant. It says she had paid taxes and National Insurance but was refused claims for jobseekers' allowance.

'Very sound'

It says UK citizens in other EU states do not have to meet similar tests and get non-contributory benefits.

Laszlo Andor, Commissioner for Employment and Social Affairs, said the EU's legal position was "very sound".

We are talking here.. about people who are inactive, people who are looking to come to the UK who are not going to work here Chris Grayling, Employment minister

"The EU insists on the right of mobile workers to move from one country to another and, in certain places, they are entitled to benefits," he told the BBC.

"We want to protect the rights of all EU citizens."

Most people moving abroad already had offers of work or were looking for it, he said, rather than primarily wanting to take advantage of more generous benefits.

"It may happen that some of them do not a find a job immediately. It is very important that, in these cases, the rights should be respected."

He added that some people might choose to move to a country where benefits were higher but "since we have a European Labour market we have to accept this as a fact".

But UK ministers fear taxpayers could be forced into handing out more than £2bn to EU nationals - including so-called "benefits tourists" - if the UK has to comply.

'Difference of opinion'

Employment minister Chris Grayling, who met EU officials this week to discuss the issue, said there was a "very definite difference of opinion" between the UK and the Commission.

"We are talking here, not about active citizens, not about people who are working but people who are inactive, people who are looking to come to the UK who are not going to work here."

He said European law was "all over the place at the moment" and the UK had separately been told by the European courts to make disability benefit payments to a British citizen living in Spain.

He said 13 EU states had proposed a "comprehensive review" of policy in the area in June and talks were continuing.

Nigel Farage, leader of the UK Independence Party, which campaigns for Britain's exit from the EU, said: "It is not discrimination but simply a system to ensure that benefits are only paid to those who are entitled to them."