Ministers have agreed to release legal advice they received on Alex Salmond's court challenge after John Swinney looked set to lose a vote of no confidence in Holyrood.

The key document which underpinned the Scottish Government’s defence of the judicial review taken by the former First Minister will be released tomorrow.

Earlier today it seemed certain the Deputy First Minister would lose a no confidence vote in Holyrood tomorrow over the matter after the Greens said they would back a motion lodged by the Tories. Labour and the Lib Dems were also set to vote in its favour.

Swinney survived a vote of no confidence last year over the awarding of exams grades last August after Patrick Harvie's party refused to back it.

However, as the SNP do not have a majority, he would have been highly unlikely to survive such a vote with the five MSPs from the Scottish Greens supporting it.

MSPs have voted twice for the legal advice to be released to a Holyrood committee - a move supported by Salmond when he appeared before it last Friday.

During the six hour question and answer session, the former first minister acknowledged that although government legal advice is usually not made public, it can be in circumstances where there is an over-riding public interest.

In a statement tonight Swinney said: “In normal circumstances, government legal advice is not released. Indeed, such is the importance of being able to get frank, private advice, it is almost unheard of for the legal advice to be released.

“But, we have to acknowledge that the issues at stake now are not normal. The very integrity of the legal system is being questioned.

“Serious allegations have been made. This material allows people to confirm that these allegations are false.

“We have already shared in private with the Scottish Parliament’s committee on these issues the substance of the advice.

“Now, we recognise that in order to counter to the false claims being made by some, we must go further. Subject to the mandatory legal checks and processes, we will release the key legal advice.”

Swinney has received the prior agreement of the government's law officers in line with paragraph 2.40 of the Scottish Ministerial Code over the release of the legal papers.

Responding to the government's announcement, Scottish Conservative leader Douglas Ross said tonight it would not be removing the no confidence motion until the documents were handed to the committee and published in full.

He said: “Despite two votes in the Scottish Parliament demanding the legal advice be published, John Swinney only backed down and u-turned to save his own skin.

"It's a pathetic reveal of what motivates the SNP. It's not about getting to the truth, it's only about self-preservation.

"But the Scottish Conservatives will not remove our no confidence vote motion until the government guarantees it will fully publish the legal advice.

“The Deputy First Minister is not in the clear yet. He must go further and fully publish the legal advice or we will not hesitate to force him out."

Ahead of release, under the General Data Protection Regulation, legal notifications to individuals impacted are also required. These are expected to be complete and, subject to them, the Parliament will receive the material immediately thereafter, the statement from the Scottish Government said.

During the committee hearing on Friday Salmond alleged there had been a "calculated and determined" effort to suppress evidence relating to the government's unlawful handling of complaints made against him. 

Samond also claimed that the government was given legal advice in October 2018 that its case would not be successful, but continued with the action at the taxpayers' expense.

He maintains such an approach was a breach of the ministerial code by Nicola Sturgeon. The First Minister has denied breaching the ministerial code and will appear before MSPs on the harassment committee on Wednesday.

In written evidence to MSPs, published last Monday, Salmond said: "Further once the Judicial Review had commenced, and at the very latest by October 31st 2018 the Government and the First Minister knew of legal advice from external counsel (the First Minister consulted with counsel on 13th November) that on the balance of probability they would lose the Judicial Review and be found to have acted unlawfully.

"Despite this the legal action was continued until early January 2019 and was only conceded after both Government external counsel threatened to resign from the case which they considered to be unstateable. This, on any reading, is contrary to section 2.30 of the Ministerial Code."

Salmond made a legal challenge to the Scottish Government over its investigation of complaints made against him through a judicial review.

The court found the government had mishandled the complaints made by two civil servants and that the process was unlawful and unfair and "tainted by apparent bias."

The former first minister was awarded more than £500,000 by the court. Salmond has also called for civil service chief, Permanent Secretary Leslie Evans, who was overall in charge of the unlawful policy and how it was implemented to resign.

MSPs on the committee on the Scottish Government's handling of sexual harassment complaints are trying to establish what went wrong in how the policy for investigating complaints was drawn up and how it wrongly implemented against Salmond.

A separate inquiry is ongoing into whether the First Minister breached the ministerial code. She denies doing so.

Taking questions at the committee on Friday, Salmond said rules were in place to allow legal advice given to the government to be released if it was "in the public interest" and pointed to previous circumstances when advice was published.

He said: "There is an understandable reason for reluctance to reveal legal advice, as a general rule, but the rules, as drawn up, provide for exceptions in the public interest.

"There have been a number of precedents in the past - I am thinking of the blood contamination inquiry, for example.

"Although every instance is going to be different, I think that most people, judging the current issue, would say that, after two parliamentary votes, that legal advice should and must be furnished.

"It might be that something should be written into either the ministerial code or the standing orders of the Parliament to make that clear. I am just amazed that you would have to go that far to ensure that that is done. The normal assumption would be that ministers would follow a clearly expressed will of the Parliament when they are able to do so."

Salmond claimed on Friday there were "malicious" efforts made against him by allies of the First Minister - including her husband Peter Murrell, the chief executive of the SNP - to mount a police investigation against him which would then publicly overshadow the unlawful judicial review ruling against the government.

However, the former first minister argued the plan failed when he was acquitted of all charges at his trial last year.

Sturgeon has dismissed his claims and accused him of "wild" conspiracy theories.