A Scottish judge at the centre of the so-called ‘magic circle’ allegations was asked to resign following claims he had allowed his "widespread" homosexual activities "to have been conducted in a public way", a previously secret file suggests.

A memo prepared for Margaret Thatcher in December 1989 states clearly that “apparently, nothing illegal has been uncovered”.

But it adds that the Lord President of the Court of Session in Edinburgh and the then Scottish Secretary Malcolm Rifkind had concluded that Lord Dervaird should be asked to resign.

The note warned the Prime Minister that the Scotland Office had been in touch to alert Number 10 to the “imminent resignation”.

It reads: “The background is speculation in press circles that three Scottish judges have been involved in a homosexual scandal.

“This has been looked into by the Lord President (of the Court of Session in Edinburgh, Lord Hope) and the Secretary of State, who concluded that Judge Dervaird should be asked to resign.

“Apparently, nothing illegal has been uncovered but he does seem to have allowed his widespread activities to have been conducted in a public way.”

Lord Dervaid stood down over what was dubbed the “magic circle” gay sex scandal.

The Scottish legal world was shocked by claims of a conspiracy between gay judges, sheriffs and lawyers.

They included allegations that criminals had received lighter sentences after they threatened to blackmail senior figures with information about their sex lives.

But an official inquiry led by William Nimmo Smith, a prominent QC, found no evidence for the claims.

In his 1993 report he said of Lord Dervaid: “It would not be untrue that he had had homosexual relations.”

But he concluded that he had “no reason to believe that Lord Dervaird’s official conduct as a judge had in any way been affected by the matters which led to his resignation”.

Following his resignation, Lord Dervaid worked as a professor at Edinburgh University.

He died in 2015.

A lawyer, Robert Henderson, who was identified as the man behind the magic circle claims, was later accused of child abuse by his own daughter.

Sir Malcolm said: “The issue at the time was not about Lord Dervaird's sexuality or about whether anything illegal had occurred. It was as to whether his behaviour had been appropriate for a senior serving judge. As you will have seen from the archives the Lord President (Scotland's most senior judge) discussed this with Lord Dervaird who agreed that he should cease to serve as a judge. As you may know Lord Dervaird, thereafter, went into legal academic life and was a distinguished professor.”

Lord Hope said that the rationale for concluding that Lord Dervaid should resign lay in the line that he had allowed “his widespread activities to have been conducted in a public way”.