Scottish authorities have won the right to rule on the fate of foreign children after rescuing an at-risk Polish baby on holiday in the country.

In a landmark judgment, the country's highest court has effectively decided that Scotland's child-protection system can claim temporary jurisdiction over at-risk youngsters visiting from overseas.

Three Court of Session judges have ended what insiders called a 'legal loophole' which meant the country's children's hearing system was powerless to deal with a growing but small number of complex international cases.

Their judgment came more than a year after social workers in Glasgow took in to care a Polish-born baby whose mother was understood to be making a 'fleeting visit' to Scotland.

They had already taken an older child in to care after evidence she had been hurt while she, her mother, and her father previously lived in Scotland.

The bab, a boy called called Child Z in court documents, was left in legal limbo for months after a sheriff in the city ruled locals courts and children's panels had no jurisdiction over him - because he was 'habitually resident' in Poland, not Scotland.

The sheriff, in a ruling last year, had feared that constant children's panels proceedings involving Child Z could effectively change his country of residence against his family's will.

However, Lord Brodie, Lord Drummond Young and Lady Clark of Calton have now ruled that the sheriff was wrong and that Scottish authorities can make decisions over such children.

The Scottish Children's Reporter Administration or SCRA, which had suffered a chain of failed referrals over Child Z to panels, had appealed against the sheriff's ruling.

Malcolm Schaffer, the organisation's head of practice and policy, said: “All parties agreed this was an important point of law to clarify.

"It ensures that where a child who is not a normal resident in Scotland comes to our country and is judged in need of urgent protection, that can be done for a period of time until his or her mother country can take over jurisdiction.

He added: "We are happy with the judgment.

"It make our powers clearer in the increasing number of cases where a child may be in our country temporarily and ensures no child in need of urgent protection will fall through a crack between two jurisdictions."

The Court of Session judgment also draws an end to the legal saga that has continued for most of Child Z's life.

Proceedings had continued at panels even as jurisdiction was disputed in courts. Child Z was returned to his mother in April after the panel found that his father, not his mother, was responsible for the injuries to his sister, who at that stage was still in Scottish foster care.

However, Child Z was subject to a Scottish interim supervision order which meant his father was not to get unsupervised access.

The Court of Session judgment suggested that Child Z's mother was also to regain custody of her eldest child, who is three, and that their return to Poland was "imminent". The Herald understands that the mother now has both children but remains in Scotland.

Noel Ferry, partner in family law at law firm Turcan Connell, which was not involved in the case, praised the Court of Session judgment.

He said: "This is a very sensible decision which allows our system to take action to protect children. Common sense has prevailed and now everybody, the courts, the panels, the SCRA and parents can be clear on where they stand."

Mr Ferry stressed that, although the Child Z case was resolved, it was crucial to get a judgment that would apply to future cases.

Social workers can and do intervene in cases involving visiting foreigners, including the relatives of Scottish residents from countries like Poland or Canada.

Normally a social worker would seek a child protection order from the courts if a child was in danger and subsequently refer the case to a children's hearing to decide the youngster's future care.

But if the parents dispute the grounds for that referral, or if the child is too young to understand it, the case must be referred to a sheriff to decide if the grounds are true. Sheriffs and panels will now be free to make such decisions and decide future fate, pending future interactions with another jurisdiction.

Justice insiders stress such international matters can take months as language and other difficulties get in the way of a fast resolution. Mr Schaffer said the SCRA was looking to beef up its foreign contacts to deal with such cases.