Scotland's national child abuse inquiry has descended into chaos after its chair Susan O'Brien QC resigned amid a furious war of words with the Deputy First Minister John Swinney.

The Scottish Government began proceedings to remove the leading lawyer from the independent inquiry in May, it has emerged.

It follows comments Ms O'Brien made during a private training session which had led a trauma expert to accuse her of a "shocking level of misjudgement".

However, Ms O'Brien decided to quit before an investigation into the comments could be concluded. She insisted she was unable to continue as inquiry's independence was being compromised by interference and micromanagement on the part of ministers and civil servants.

In a letter to Mr Swinney yesterday, she said: "My position as independent chair of this inquiry has been actively undermined by some Scottish Government officials over the past months."

Her comments echoed those of Professor Michael Lamb, the senior psychologist who quit the three person panel heading up the inquiry last week, also alleging that its interference and had made its work impossible.

The government said the third panel member, Glenn Houston, would continue in his role, although he is understood to have written in support of Ms O'Brien and opposed her dismissal.

Mr Swinney's bid to remove Ms O'Brien as chair was triggered by a series of letters from a senior psychologist Dr Claire Fyvie, head of service at the Rivers Centre, at the Royal Edinburgh Hospital.

The centre had been asked to bid to provide support for participants in the inquiry who might be traumatised by giving or listening to evidence, but Dr Fyvie wrote an explosive letter to the inquiry in May refusing to bid, citing comments made by Ms O'Brien at a training session in February.

Towards the end of a session Ms O'Brien had commented that someone affected by childhood abuse in a boarding school had described it as "the best thing that had ever happened to [them]".

Dr Fyvie said that on the same day Ms O'Brien had discussed a teacher put on trial for abuse and suggested "that the teacher in question had simply had a hole in his trousers."

The psychologist said of both comments: "Whilst I accept that these remarks may have been well-intentioned, I believe they are totally unacceptable and indicate a belief system that is incompatible with the post of Chair of a child abuse inquiry."

She went on to say that as a result, beyond an existing short term contract, the Rivers Centre would no longer work with the abuse inquiry.

In a letter to Dr Fyvie, Colin MacAulay QC, Susan O'Brien's lawyer asked for the allegations to be withdrawn, describing them as "defamatory and actionable".

But government appears to have accepted that her position would be untenable should such comments, or similar ones, be made public and began the legal procedure necessary to remove her as chair of the Scottish Child Abuse Inquiry.

In a subsequent letter, in which the recipient's name has been redacted, Dr Fyvie refused, adding: "The chair has threatened to raise legal proceedings against me unless I apologise and withdraw my statements. I intend doing neither.

"I have worked in the NHS for nearly 30 years now and have never before taken action of this kind."

She also repeated her concerns about Ms O'Brien's remarks, describing them as demonstrating "a shocking level of misjudgement."

In her resignation letter to Mr Swinney, the QC admitted the controversial comments had been made but said they had been taken out of context and her intention misunderstood.

She had refused to resign when asked to do so, she said "as I have done nothing wrong," and said she had reassured Mr Swinney personally at a meeting on June 28th that "I did not underestimate the gravity of child abuse. I would never do so."

She also says the inquiry's work has been hampered by interference, particularly in relation to expenditure. When figures were last published in March, as it began to take evidence, the inquiry had already cost more than £1.1 million

Ms O'Brien said the proposal to dismiss her as chair left her with no confidence in the minister. "My trust that the Scottish Government will actually respect the independence of the inquiry has gone," she added.

As the war of words broke out, groups representing abuse survivors said they were shocked and angry at the situation. Alan Draper, of the group In Care Abuse Survivors Scotland said: "This is a shambles of the government's making."

Andi Lavery, of the survivors' group White Flowers Alba called for a review of the whole inquiry and called for an end to the maltreatment of those who have suffered abuse as children.

David Whelan of Former Boys and Girls Abused said: "If Ms O'Brien has made the comments attributed to her, that is disgusting. But the Scottish Government have to do something now to restore the confidence of survivors."

In a statement Mr Swinney said it had been impossible for Ms O'Brien to continue, but continued to deny the government had interfered in the independence of the inquiry: "Our priority has always been to support the successful operation of the Inquiry, ensuring it continues to make progress," he said.

"Sadly, the comments of the chair raised serious concerns. The comments made were considered by a leading abuse trauma expert to be totally unacceptable and to indicate a belief system that is incompatible with the post of chair of such an inquiry; to be offensive to survivors and to lack any context in which they could be seen as acceptable."

He said the chair' s "actions" had the potential to cause the loss of confidence of survivors, who he said were the very people at the heart of the inquiry.

“Given the severity of those concerns, I felt I had a duty to initiate statutory proceedings which could have led to removal of the chair from post," Mr Swinney added. “This government absolutely rejects any charges of interference in the independence of the inquiry."