London: A European citizen who becomes a British citizen does not lose the right to have a spouse from a non-EU country live with them in the UK, the European court of justice (ECJ) has ruled in a landmark case.

After a five-month deliberation it has decided the Home Office was wrong to refuse a dual British-Spanish citizen the right to have her Algerian husband live with her in the UK.

Immigration barristers say the ruling will have widespread implications for EU citizens applying for British passports and those married or considering marriage to a third-country national.

“This is great news for EU citizens who have moved to another European country because it enables them to benefit from sensible EU rules on being joined by family members,” said the immigration barrister Colin Yeo, an expert on freedom of movement.

“The court has held that the UK has been wrong to refuse to recognise free movement rights for all those EU citizens who have been naturalising as British following the Brexit referendum. After Brexit, though, all those rights will be lost unless an agreement is reached to retain them.”

The case of Garcia Ormazabal and her husband, Toufik Lounes, was referred to the European court by the high court in London last year after the Home Office rejected an application by the Algerian for permanent residency in the UK.

He had come to the UK in 2010 on a six-month visa and then overstayed illegally.

Ormazabal moved to the UK as a student in 1996 and has been working in the country full time since 2004. She became a naturalised British citizen in 2009 but also retained her Spanish nationality.

The Home Office had argued that Ormazabal’s rights under the freedom of movement directive no longer applied when she became a British citizen in 2010 and that she should be treated like any other British national living in the country who would have to go through strict immigration procedures to assess whether her husband qualified to be in the UK.

They argued that domestic immigration laws applied instead and therefore he was not entitled to apply for permanent residency under EU legislation.

Related: UK wrong to deny residency rights in test case, EU’s legal adviser says

The ECJ ruled that the European directive governing Ormazabal’s rights did cease to govern her residence in the UK.

However it concluded that her husband had a “derived right” under freedom of movement rules.

It said that if the freedom of movement rules were to be effective, European citizens such as Ormazabal, who move to another member state and acquire citizenship of the country, must be able to continue to have the right to build a family.

She took the Home Office to court, but last year the high court referred the Lounes case to Europe asking the court to decide whether the British government had breached the freedom of movement family rights.

The high court told the ECJ that it had doubts as to the compatibility of the Home Office’s decision and UK legislation with EU law and sought direction from the European court on the application of its own laws.

The case was of such significance that Spain and Poland, as well as the UK home secretary, made legal submissions during the summer.

In its judgement the ECJ notes that the EU directive on freedom of movement family rights does not confer rights on EU citizens who have not exercised those rights by moving to another country within the bloc.

But it does confer those rights on an EU citizen who has moved to another country and these are the so-called “derived rights”.

It said that denying Ormazabal these rights on the grounds that she had become a British citizen was legally faulty.

This interpretation of European law “would amount to treating Ms Ormazabal in the same way as a British citizen who has never left the UK, disregarding the fact that she has exercised her freedom of movement by settling there and that she has retained her nationality of origin,” it said.