The Appeal Court has overturned a ruling that expert witnesses should be exempt from disciplinary action by their regulatory body.
Sir Roy was initially struck off the medical register
The issue was debated following the case of Professor Sir Roy Meadow.
The paediatrician was struck off after giving flawed evidence at Sally Clark's 1999 trial for the murder of her sons.
The High Court previously ruled that regulatory bodies such as the General Medical Council could not punish expert witnesses over "honest mistakes".
The GMC said that ruling rendered it "toothless", preventing it from doing its work comprehensively, and establishing a principle which would affect other regulators.
The Attorney General, Lord Goldsmith, supported the GMC's case. He said it was not up to a court to decide if expert witnesses should escape punishment.
However, the three Appeal Court judges also ruled that the High Court decision that Sir Roy was not guilty of serious professional misconduct should stand.
The GMC had initially found the evidence that the retired paediatrician gave in the case of Sally Clark was so flawed that he was guilty of serious professional misconduct, and so he was struck off the medical register.
Sir Roy, speaking outside the court, said: "I am glad that the Court of Appeal has agreed with the previous High Court judgement that my evidence which I gave in the course of the trial of Mrs Clark nearly seven years ago was not an example of serious professional misconduct, and that the GMC was wrong in its judgement."
He said the ruling was important for paediatricians and all doctors, nurses and other professionals who may have to give difficult and sometimes unpopular opinions in the course of giving evidence in court.
"Children can only be protected from abuse if those who suspect abuse are accorded the presumption of good faith when they report their suspicions, write reports, or give carefully considered opinion in court; and if they can do so without fear of unreasonable prosecution."
But Frank Lockyer, Sally Clark's father, said Sir Roy's comments were "totally disingenuous".
The GMC said it was "delighted" it had won back the right to discipline doctors who appeared as expert witnesses.
Chief executive Finlay Scott said: "This appeal was about protecting the public interest.
"The public must be confident that doctors and other professionals who give evidence in court proceedings can if necessary be held to account by their regulator.
"We did not accept that the GMC should be prevented from using its statutory powers when we judge it to be necessary, and the Court of Appeal has confirmed that we were correct."
The Royal College of Paediatrics and Child Health welcomed the court's decision, including rules for the GMC aimed at "reducing the risk of expert witnesses being deterred from acting in good faith in their responsibilities in safeguarding children".
But Tom Magner, of the Society of Expert Witnesses, said: "The court gives immunity. Now it seems a professional regulatory body can take it away.
"That doesn't seem natural to us."
Mr Magner said he feared regulators would look at evidence out of the context, and so not be able to evaluate how factors such as barristers' questioning might have affected what an expert said in court.
Sir Roy gave evidence at the trial of Sally Clark, who was arrested in 1998 after the deaths of her two sons, Christopher and Harry.
He told a Chester Crown Court jury during her trial there was a "one in 73 million" chance of two children dying from cot deaths in an affluent family.
Mrs Clark's conviction was later quashed in the Court of Appeal on grounds unrelated to Sir Roy's evidence.
But the High Court over-turned the decision in February, and said the GMC should not even have pursued the complaint.