A council has lost its legal bid to gain parental rights over a child whose parents have learning difficulties.

The girl's parents appealed to the UK Supreme Court after Scotland's highest court upheld a decision to grant West Lothian Council a permanence order for her.

This order extinguished the parents' rights and responsibilities, transferring them to the local authority.

It also specified there should be no contact between the child and her parents and included an order granting authority to adopt.

Born in 2013, the girl, referred to as EV, has been in care since her birth.

West Lothian Council applied for the permanence order following concern about her father, who in 2010 was charged with criminal sexual conduct with another learning disabled person of a similar age, although the charges were dropped.

The parents appealed against the decision but the Inner House of the Court of Session upheld the permanence order, though it quashed the authority to adopt and removed the prohibition on contact.

The mother and father then further appealed to the Supreme Court, which on Wednesday issued its judgment refusing the petition for a permanence order.

Judges found the decision was "deficient in a number of respects" and did not determine the threshold issue which must be considered before making a permanence order.

According to the test, the court must not make an order unless it considers it would be better for the child that the order be made than it is not.

It must also be satisfied, in relation to each of the parents, that the child's residence with that person is likely to be "seriously detrimental" to her welfare.

In a statement, the judges said: "Although much was said about the local authority's concerns about the father's behaviour years earlier, nothing was said, for example, about how the child's current foster care arrangements were working or about the prospects of a suitable adoptive placement being found.

"There was no analysis of the merits of her living with a foster carer, who has no intention of adopting her, as compared with her living with her parents.

"At the most basic level, the possibility of her parents being able to offer her a permanent home might have been a relevant factor, particularly if the prospects of her being adopted were poor, to set against the negative factors."

The Lord Ordinary heard evidence from social workers that even with their extensive support, the mother, who has two children by a previous partner, "might only even master physical care tasks and not manage the more complex tasks of meeting EV's emotional and social needs".

Social workers were concerned about the mother's ability to meet EV's emotional and social needs and the father's ability to acquire parenting skills.

They said it is apparent the local authority still considers adoption is the best option for the child.

The judges concluded: "In these circumstances, the most sensible way forward is for this court to allow the appeals and refuse the petition, leaving it to the local authority to commence fresh proceedings as and when that may be appropriate."

A West Lothian Council spokesman said: "We are considering the terms of the court's decision and its possible implications for future permanence applications. It is not appropriate to comment on individual cases."