Nearly £20,000 of public money was spent in a court battle over legal advice that did not exist.

Scottish Ministers rejected a ruling by Scotland's Freedom of Information enforcer which compelled them to reveal whether it had taken legal advice to support its insistence that Scotland will continue in the European Union if it becomes independent.

Ministers referred the ruling to the Court of Session, claiming that the Scottish Information Commissioner had erred in law, but later abandoned the action and revealed that they had not taken any specific legal advice on Scotland in the EU.

Deputy First Minister Nicola Sturgeon has now revealed that the case cost nearly £20,000 in legal fees.

Responding to written question by SNP MSP Clare Adamson, Ms Sturgeon said: "The total cost incurred by the Scottish Government was £19,452.92. This breaks down as Scottish Government's legal costs for Counsel of £3960 including VAT, law accountant fees of £1680 and Information Commissioner's fees of £13,812.92."

Specific law officer advice on Scotland's potential future in the EU now exists, but the Scottish Government has declined requests to make the advice public.

Scottish Labour constitution spokesman Drew Smith said: "It's outrageous that the SNP has used public funds in an attempt to hide the truth ahead of the referendum. They're increasingly fond of using public funds for their own vanity projects, from trips to the golf, tartan trews and now to deceive on the constitution."

The Scottish Government said the case was about a point of law which both the Commissioner and Scottish Government needed to clarify.

A spokesman for External Affairs Minister Humza Yousaf said: "This is the height of hypocrisy from Labour and the Tories - both of whom made utterly false claims in Parliament that these costs were more than £100,000. When Labour and the Lib Dems were in office in Scotland they took five FOI cases to court in just two years, costing around £30,000, compared to just two cases in five years under this administration."