By Dominic Casciani
The EU's highest court said a child's education was paramount
The European Court of Justice has said some migrant families can stay in the UK and claim benefits - even if the main worker has left the country.
The court, which deals with EU law, said some families must be allowed to stay when their child was in education.
A child's education was paramount, so parents could not be told to leave if they could not support themselves.
The Home Office said it was disappointed with the ruling but would not be drawn on its implications.
The judgement could lead to more foreign national families claiming a right to remain, even if they are not working and have no ties here other than children in education.
The ruling comes after a protracted legal battle by two families over the right to education and public services in the UK.
In the first case, a Somali woman, Nimco Hassan Ibrahim, arrived with her children in the UK in 2003 to join her husband.
He was a Danish citizen working legally in the UK under the European Union's standard rules governing freedom of movement.
Ms Ibrahim's husband left the UK in 2004 and the couple separated. Ms Ibrahim and the children, who also had Danish citizenship, stayed in the UK.
The court said she had never been self-sufficient, and relies on benefits and housing support for herself and her children.
In the second case, a Portuguese woman, Maria Teixeira, joined her husband in the UK in 1989 and their daughter was born in the country two years later.
The couple later divorced and, years later, Ms Teixeira challenged a council's decision to deny her housing benefit.
Lawyers for Ms Teixeira told the court she had a right to residence because of her daughter's continuing education.
'Right of residence'
Harrow and Lambeth councils in London both fought the families' legal challenges, supported by the Home Office.
But in its judgement, the Luxembourg court said that a foreign national parent who was caring for a child in education had a right to live in the UK.
That right applied even if the parent who was working was no longer part of the family and the parent who was the carer had no individual claim to live in the country.
It said that it backed the two families because European Union law clearly stated that it would be unjust to interfere with a child's education once it had legally begun.
The judgement said: "The court finds that the right of residence of the parent who is the primary carer of a child of a migrant worker who is in education is not conditional on that parent having sufficient resources not to become a burden on the social assistance system of the host member state."
A Home Office spokesman said: "We are disappointed with today's ruling.
"We will now consider closely the European Court judgments and their implications."