MSPs have demanded the Scottish Government disclose its legal advice behind its doomed legal battle with Alex Salmond.

In a humiliating, but ultimately non-binding, defeat for Nicola Sturgeon and her ministers, Holyrood backed the Tory proposal by 63 votes to 54.

There were five abstentions.

It followed claims the advice could clear up whether the Government abused public funds in a “sinister” way to pursue a “vendetta” against Mr Salmond, as his supporters have claimed.

Deputy First Minister John Swinney had argued publication was against the public interest as it might stop ministers getting full and frank advice in future.

He said he would consider the vote with ministerial colleagues in light of his duties under the Scottish Ministerial Code, which MSPs heard could stop him publishing it if the Government's law officers objected.

The vote came after months of behind-the-scenes frustration at the Holyrood inquiry into the Salmond affair and a running battle with ministers and officials over their evidence.

The cross-party committee is examining how the Government botched a probe into sexual misconduct claims levelled against Mr Salmond by two civil servants in 2018.

The former First Minister had the exercise set aside in a judicial review after showing it had been “tainted by apparent bias”, a victory that left taxpayers with a £512,000 bill for his costs.

After the Government’s case collapsed in January 2019, Ms Sturgeon gave an undertaking to parliament to “provide whatever material” the inquiry requested.

She said: “That is the definition of full, thorough and open inquiries. My commitment is that the Government and I will cooperate fully with it.”

But her officials and ministers have since tried to block witnesses and withhold evidence.

In particular, the Government has refused the committee’s request for the legal advice on which it decided to defend the civil action for  the best part of a year. 

Ministers have cited “legal privilege” for doing so, despite waiving it for three judge-led inquiries on contaminated blood, historical abuse and Edinburgh’s trams. 

The Tory motion called on the Government to “publish all the legal advice it received regarding the judicial review into the investigation of the alleged behaviour of the former First Minister, Alex Salmond.”

Tory MSP Murdo Frasers said there “nothing in law” preventing the Government publishing the legal advice, only a long-standing convention that it had waived on previous occasions.

He said that if the advice said the Government had a good case to defend, then lessons needed to be learned about obtaining better advice. However there was a “much more sinister and concerning” possibility.

He said: “Mr Salmond’s allies believe that the legal advice obtained by the Scottish Government told them that the judicial review case should not be defended, as there was very little chance of success.

"And if that is indeed what the legal advice said, then it means that a decision was taken at the top of the Scottish Government to go and defend the case regardless, a decision which was both irresponsible and reckless.

“More worrying still is the accusation that that decision was made on political grounds and in effect the Scottish Government were pursuing a vendetta against the former first minister and using public funds to do so.

“Now that claim may well be nonsense.

"But it is impossible for members of the committee or the public as a whole to reach a view on which of these explanations is the correct one in the absence of the legal advice, and that is why it’s publication is so vital to the inquiry.”

After the vote, Mr Fraser said: "This sends a clear message that the SNP don’t get to make their own rules and decide what constitutes transparency.

“The government has so far treated the Salmond inquiry with contempt. It has refused at every turn to release key evidence and kept the legal advice hidden.

“As a result, we don’t know if £500,000 of public money was handed to Alex Salmond because of sheer incompetence, faulty legal advice or something more reckless and sinister.

“Nicola Sturgeon promised to ‘cooperate fully’ with the inquiry. If her words mean anything and if she respects the will of Parliament at all, the government must publish the advice."

Liberal Democrat MSP Alex Cole-Hamilton said: "It's important to remember that the Judicial Review wasn’t about whether Salmond was guilty, but rather if due process had been followed by the government.  

"If the Scottish Government were warned that their process was flawed, then they should have picked a different course and not cost the taxpayer more than £500,000.

"Instead there are suspicions that they deliberately allowed this to play out in public. This did not serve Mr Salmond, the complainants or the Scottish taxpayer well.

"Parliament has made quite clear that on this occasion it expects the legal advice to be handed over to the Salmond inquiry. It will be interesting to see whether its contents match the claims made by Scottish Government ministers and officials."

Green MSP Andy Wightman said the elected parliament was a better barometer of the public interest than the Government, who were an “interested party”.

Labour MSP Jackie Baillie, who sits on the inquiry, said the Government had been “obstructing” its work.

She said: “It is very much Secret Scotland with this Government. It is time for the Scottish Government to end the secrecy. Give the Committee the legal advice or tell the people of Scotland what it is that you have to hide.”

After the vote, Mr Swinney told MSPs: "In light of the vote that we've just had on the Conservative motion on the committee on harassment, let me confirm that ministers always seek to respect the decisions taken by parliament.

"I will now consider the implications of the motion with my ministerial colleagues, consistent with our obligation in the ministerial code, and will advise parliament accordingly in response."

Earlier, former SNP health secretary Shona Robison had warned it would be a breach of the code to release the advice if the Government's law officers objected.