A non-EU parent has a right to stay in the bloc if their child is an EU citizen, the European Court of Justice has said in a ruling that could complicate Brexit talks.

The ECJ said national courts must focus on the welfare of the child and the "risks which separation from the [non-EU parent] might entail for that child's equilibrium".

The European Union insists that the rights of more than three million EU citizens in Britain be among the very first issues settled in the Brexit divorce negotiations due to start shortly.

One of Britain's main gripes in the lead-up to Brexit has been over the role of the ECJ, especially on migration issues.

The court was ruling on the case of a Venezuelan woman who entered the Netherlands as a visitor but subsequently had a child with a Dutch national.

They moved to Germany but after the relationship failed in 2011, the woman, identified only by her last name, Chavez-Vilchez, said she became solely responsible for the welfare and upbringing of the child.

However, since she did not have a right of residence in the Netherlands, the authorities there rejected her application for social welfare and child benefit payments.

In a statement, the Luxembourg-based ECJ said it was up to the Dutch courts to decide whether Chavez-Vilchez had "a derived right of residence".

But if the Dutch court ruled that she did not have this right, then "her situation and that of her child must be examined... in the light of Article 20" of the EU's treaty.

The ECJ said case-law had established that Article 20 "precludes national measures, including decisions refusing a right of residence to the family members of an EU citizen".

If Chavez-Vilchez and other mothers in a similar position were forced to leave, "that could deprive their children of the genuine enjoyment of the substance of those [EU] rights by compelling those children to leave the territory of the EU".

The ECJ said that even if the EU parent was able and willing to look after the child, that was "not in itself a sufficient ground" to believe the child would not be compelled to leave the bloc if the non-EU parent was barred from residence.