The Supreme Court has ruled a scheme by the Scottish Government to impose a state guardian on every child is "unlawful".
The Named Person scheme was deemed to breach rights to privacy and family life after Christian campaigners appealed to the UK's highest court. The case had been dismissed by the Court of Session in Edinbugh last year.
Judges gave the Scottish government 42 days to rectify the legislation which, if passed, would have appointed a named person, normally a teacher or health advisor, to every child in Scotland. It included powers to access and share private data on children and parents and provide "advice".
Judges said the aim of the programme was "unquestionably legitimate and benign", but said specific proposals about information-sharing "are not within the legislative competence of the Scottish Parliament". They said it "cannot be brought into force" until amendments are made.
Critics see the programme as a Big Brother-style intrusion into private and family life.
In a damning judgement, the court said: "The first thing that a totalitarian regime tries to do is to get at the children, to distance them from the subversive, varied influences of their families, and indoctrinate them in their rulers' view of the world. Within limits, families must be left to bring up their children in their own way."
A coalition of charities led by The Christian Institute formed the No to Named Persons (NO2NP) campaign and brought the appeal to the court. They argued the scheme was an "unjustified and unjustifiable state interference with family rights".
Colin Hart, director of The Christian Institute, said he was "very happy" with the result which would "come as a great relief to millions of people".
He added: "The ruling protects families all across the UK from unwarranted invasion of their privacy by the state. We urge local and national government agencies to read the ruling carefully and amend their policies and practices to ensure they properly respect the privacy and autonomy of innocent families."
The Scottish Conservatives have also opposed the scheme and called for Nicola Sturgeon, First Minister of Scotland, to "swallow her pride" and scrap the programme.
But Scotland First Minister's John Swinney said the "attempt to scrap the named person service has failed" and vowed to carry on with the scheme as soon as possible.
""The court's ruling requires us to provide greater clarity about the basis on which health visitors, teachers and other professionals supporting families will share and receive information in their named person role," he said after the judgement. "We will start work on this immediately so we can make the necessary legislative amendments. The service will be implemented nationally at the earliest possible date."