Ex-children's services director Sharon Shoesmith says she is "thrilled" to have won a Court of Appeal battle over her sacking after Baby Peter's death.
Judges said then children's secretary Ed Balls and her employers, Haringey Council, had been "procedurally unfair" when they sacked her three years ago.
The education department and Haringey plan to appeal to the Supreme Court.
Baby Peter Connelly, who had been seen 60 times by social services, was found dead in 2007 with over 50 injuries.
Ms Shoesmith's appeal was challenging a High Court ruling that cleared Ed Balls, the north London borough of Haringey and watchdog Ofsted, of acting unlawfully.
The Court of Appeal judges dismissed her appeal against Ofsted.
Mr Balls said he "strongly disagreed" with the judgement and added that his decision had been based on a report from independent inspectors.
Ofsted said its report on Ms Shoesmith's department, which identified "insufficient strategic leadership and management oversight", had been vindicated.
A Haringey Council spokesman said it was "deeply disappointed" by the judgement and stood by everything it had done.
Sacked on TV
In December 2008, Ms Shoesmith - originally from Newtownabbey, County Antrim - was sacked, bringing her 35-year career to an abrupt end.
She said she first heard of her dismissal when Mr Balls announced she would be removed from her post with immediate effect in a live press conference on television.
After the hearing, she said: "I'm over the moon. Absolutely thrilled.
"I am very relieved to have won my appeal and for recognition I was treated unfairly and unlawfully."
She said the sorrow of Peter's death would "stay with me for the rest of my life".
"But as the judges have said, making a 'public sacrifice' of an individual will not prevent further tragedies," she added.
At a hearing in March, Ms Shoesmith had asked Lord Neuberger, Master of the Rolls, sitting with Lord Justice Maurice Kay and Lord Justice Stanley Burnton, to rule that her sacking without compensation was so legally flawed as to be null and void.
Her lawyers had argued that she was the victim of "a flagrant breach of natural justice" after she lost her £133,000-a-year post amid a media storm.
Ms Shoesmith also argued she was entitled to her full salary and pension from Haringey up to the present day.
'Tainted by unfairness'
In court, James Eadie QC, appearing for the government, defended Mr Balls, saying urgent action had to be taken following the "ghastly findings" of the Ofsted report.
But the judges allowed Ms Shoesmith's appeal against the former children's secretary because "the secretary of state did not afford Ms Shoesmith the opportunity to put her case".
"In short, she was denied the elementary fairness which the law requires," they said.
They also rejected a submission that the situation had been too urgent to allow for a fairer procedure to be adopted.
In the case of Haringey, the judges said: "We were unanimously of the view that Haringey's procedures were tainted by unfairness."
Lawyers for Ms Shoesmith said the ruling meant she could now launch appeals against Mr Balls and Haringey Council.
The BBC's education correspondent Reeta Chakrabarti said the Court of Appeal had indicated there was no question of Ms Shoesmith returning to her position at Haringey Council.
The matter of compensation or lost earnings would need to be considered by another court, she added.
Earlier, the court heard Ms Shoesmith had not been able to find work since she was sacked, had experienced suicidal thoughts and continued to be vilified by the press.
Outside court, she said: "I would love to go back to work (in Haringey) but that's not possible. I hope to carry on with my career with children in some capacity."
In a later interview with BBC London, Ms Shoesmith said she had received death threats in the wake of the Baby Peter case that had "terrified" her.
"The police were advising me that I was probably at risk," she said. "And when people begin to take photographs of you on the trains and on the buses and point you out and start to shout, 'That's that woman,' you're fearful of where that can go."
Mr Balls said he did not "rush to judgement" because the independent inspectors' report "catalogued catastrophic management failures on such a devastating scale" that the council leader and member for children services had resigned.
"I judged, on the basis of that independent report - and on the advice of departmental officials and lawyers - that the right and responsible course of action was for me to use my statutory powers to remove the director of children's services from her position with immediate effect," he said in a statement.
He said he had been doing "what was necessary to protect the interests of children in Haringey and protect wider public confidence in child protection".
In the case of Ofsted, the judges concluded its damning report "complied with the requirements of statute and common law".
Head of Ofsted, Christine Gilbert, said she was pleased with the appeal court ruling, and added: "Ofsted carried out a robust inspection and came to a sound conclusion based on evidence.
"On any view, our inspection report was extremely critical and there has been no challenge to the finding that services for children in Haringey were inadequate."
Seventeen-month-old Baby P, subsequently named as Peter Connelly, was found to have suffered fractured ribs and a broken back after months of abuse at home. His mother, her partner and a lodger were all jailed for causing or allowing his death in August 2007.
Peter had been seen by health and social services professionals from Haringey council 60 times in the eight months before he died.