The measure, which will allow Britain to restrict the access of EU migrants access to in-work benefits for four years, is likely to be judged as illegal discrimination by the European Court of Justice, say legal experts.

Instead, Mr Juncker's office devised an “emergency” measure that will be in place for just seven years, which officials said reflects the fact that the UK did not make use of seven-year transitional controls to stem the movement of eastern European migrants when the EU enlarged in 2004. Migrants' entitlement to benefits will increase over the period under a gradiated system.

“To defend in court it has to be as limited as possible,” the source said.

Mr Juncker, appearing at a press conference after the deal was signed on Friday, insisted: "I do believe decision will hold up in Court, as it respects basic principles of Treaties."

However, Steve Peers, a professor in EU law at the University of Essex, said it was a “long shot” for the plan to survive any challenge.

“While the Court of Justice has been willing to accept certain limits to free movement rights on the grounds of protecting health systems, this would have a much more far-reaching impact on non-discrimination for workers,” he wrote on his blog.

"It’s certainly conceivable that by analogy from the Court’s obvious willingness to keep EU monetary union afloat, along with its endorsement of restrictions for non-workers in recent years, it might accept that these plans do not violate the Treaties. But as EU law currently stands, that is probably a long shot."

Open Europe, the think tank, said the policy is open to legal challenge. Charles Grant, of the Centre for European Reform, said officials in London and Brussels expect a case to be brought, but added it is “highly likely to endure” because it has the backing of national leaders.

It is one of a number of hurdles that means the policy could take years to implement.

President of the European Parliament Martin Schulz Photo: Getty Images

The new law will be drawn up by Mr Juncker’s office, and then has to be approved by the European Parliament. Martin Schulz, the parliament's president, vowed on Thursday to "fight against discrimination between EU citizens."

"This safeguard mechanism would mean that two workers, both EU nationals, both paying the same taxes, doing the same work, would for a certain time not be paid the same," he said.

"This safeguard mechanism would mean that two workers, both EU nationals, both paying the same taxes, doing the same work, would for a certain time not be paid the same"

Martin Schulz

Then, in order to be activated, a vote will be held in the Council of Ministers, most likely under a qualified majority system that has a threshold of 55 per cent of states representing 65 per cent of the population.

That means the brake could be blocked by eastern European states, particularly if a major power such as France abstained.

Finally, the policy will have to be delivered by the Department for Work and Pensions. Senior British officials warned of chaos, particularly after the fiasco over Universal Credit which cost the department billions. Some benefits computer systems are currently unable to distinguish between Britons and other EU claimants, sources said.

"I would imagine, if I was a DWP computer buff looking at this text I’d think, bloody hell, how on earth are we going to do that?" said a government source. “You’ll have to re-program a lot of stuff in DWP computer systems."