Nicola Sturgeon’s closest aides were on the cusp of being questioned under oath when the Scottish Government threw in the towel in the Alex Salmond case, it has emerged.

The First Minister’s chief of staff Liz Lloyd and principal private secretary John Somers had been due to give evidence in a closed court on Monday.

READ MORE: Nicola Sturgeon and Alex Salmond at war over £500k legal case 

The pair were to have been questioned about a tranche of previously secret government documents which had been opened at the insistence of Mr Salmond’s legal team.

The documents revealed the extent of contacts between Judith MacKinnon, the investigating officer who examined the misconduct complaints against Mr Salmond, and his accusers.

The Scottish Government was ordered to surrender the evidence to an independent QC in December after initially withholding the content.

As part of this commission for documents process, it is understood Leslie Evans, the permanent secretary, was questioned under oath at the Court of Session in private.

With Ms Lloyd, the First Minister’s closest political adviser, and Mr Somers also due to be questioned, the Scottish Government contacted Mr Salmond’s legal team last Thursday.

A source said the government asked if the pair were still wanted in court, and when Ms Salmond’s side they were, the government promptly abandoned its defence and the case collapsed.

The person that the timeline was highly instructive.

READ MORE: Nicola Sturgeon backs Permanent Secretary in Alex Salmond case 

The incident shows how close Mr Salmond’s case had come to his successor’s office, potentially shedding a new light on her government’s eleventh-hour climbdown.

Mr Salmond referred to the process obliquely outside court, when he criticised the government for its “lack of candour” in the judicial review.

He linked the government’s “total surrender” to the commission for documents “which met between Christmas and New Year, where civil servants under oath had to produce hundreds of documents that the government had refused before that to provide to the court”.

Ms Lloyd, known as a tough operator at Holyrood, was head of media at the SNP for five years after the party took power in 2007, before becoming Mr Salmond’s special adviser in 2012.

She has been Ms Sturgeon’s chief of staff for four years.