Mr Justice Foskett dismissed Sharon Shoesmith's High Court challenge today - but admitted he did so with a "lurking sense of unease".
He concluded his 200-page judgment with a grave warning that his ruling would have been very different if there had been stronger evidence that Ms Shoesmith had been made a scapegoat for failings in the Baby P case.
The judge said: "I cannot think that any party will truly look back at how matters were handled in this case with complete satisfaction."
He highlighted arguments by Ms Shoesmith's lawyers that she lost her job as children's services director of Haringey Council in north London through being "in the wrong place at the wrong time".
"It is possible that there is at least a grain of truth in the suggestion," he said.
The judge noted that a paediatrician failed to spot that 17-month-old Peter Connelly - who was on Haringey's at-risk register - had a broken back shortly before his death in August 2007.
He said: "Had Dr Sabah Al-Zayyat diagnosed correctly Peter's physical condition a few days before he died, the chances are that he would have lived and the claimant and her colleagues may not have faced what they have had to face as a result.
"The child protection system in Haringey might in the meantime have acquired at least an established 'adequate' status in Ofsted terms before something as tragic as the death of a young child occurred."
Ms Shoesmith might also have avoided public hostility if she had been "more overtly apologetic" at a press conference held after the trials of those responsible for Peter's death, the judge said.
Mr Justice Foskett ruled that Ms Shoesmith's judicial challenge against regulator Ofsted and Children's Secretary Ed Balls had not succeeded.
But he said: "I will not disguise the fact that I have reached those conclusions with a lurking sense of unease."
The judge commented on claims by Ms Shoesmith's lawyers that Ofsted rewrote a report on Haringey's children's services under political pressure to make it more critical of her.
He noted: "A concerted mission to make someone a scapegoat for the failings of others, or for the failings of a system that was doomed to be characterised as a failure in any event, is repugnant to ordinary notions of fairness and justice in a civilised society.
"The law will always do what it can to overturn the consequences of such an exercise if it is shown to have occurred.
"If there had been a sustainable case that the Ofsted report had been 'made to order' at the instance of, or on behalf of, the Secretary of State and that the results of the inspection were thus either a foregone conclusion or had been manipulated to give grounds for his decision, the outcome of this case would have been different."
But he said the evidence before him was not strong enough to back up these suspicions.
The judge also criticised the arrangement under which Ms Shoesmith was sacked, with Mr Balls first removing her from her post as Haringey's children's services director and the council sacking her seven days later.
He said: "The court is left having to try to fill a gap in the procedures that is not easy to fill.
"There is, as it seems to me, a danger that someone in a position such as that occupied by the claimant will fall between two stools."
But Mr Justice Foskett reserved his final words for the little boy whose horrific death was at the heart of the case.
He concluded: "When thinking of those who were in the wrong place at the wrong time, sadly, tragically, but inevitably, one can reach no other conclusion than that was so for Peter."Reuse content