Part of the Scottish Government’s alternative Brexit legislation has been ruled to be outside of Holyrood’s powers.

Supreme Court judges in London said while the Scottish Bill “as a whole would not be outside the legislative competence of the Scottish Parliament” a key section of it could limit Westminster’s ability to make laws for Scotland.

After the judgment was issued, Scottish Secretary David Mundell said the verdict proved the UK Government had done the “right thing” by bringing the legal challenge.

Scottish Constitutional Relations Secretary Mike Russell accused Westminster politicians of carrying out “an act of constitutional vandalism”.

The Scottish Government believes MSPs were entitled to pass the legislation when it was approved in March but claimed the UK Government’s subsequent legal challenge to the Bill gave it the time to change Holyrood’s powers.

Mr Russell said: “For the first time ever, UK law officers delayed an act of the Scottish Parliament from becoming law by referring it to the Supreme Court.

“Then the UK Government, for the first time ever, invited the UK Parliament to pass a Bill which they knew would cut the powers of the Scottish Parliament without its consent.

“The UK Government changed the rules of the game midway through the match.”

He blasted: “This is an act of constitutional vandalism but that does not take away from the fact this judgment makes clear MSPs were perfectly entitled to prepare Scotland’s laws for Brexit at the time this Bill was passed.

“The UK Government’s arguments have been clearly rejected.”

He insisted the Scottish Government had been “vindicated by the Supreme Court judgment, which confirms that the Scottish Parliament had the competence to prepare its own laws for Brexit when the Continuity Bill was passed”.

Mr Russell added: “Worryingly, parts of the Bill have been thwarted as a result of steps taken by the UK Government.”

Scottish First Minister Nicola Sturgeon  described the ruling  on the European Union (Legal Continuity) (Scotland Bill) – which MSPs passed in March – as “an important vindication for @ScotGov”.

She said on Twitter the Supreme Court had found “with the exception of just one section, the Scottish Continuity Bill WAS within @ScotParl competence at point of introduction”.

Scottish Secretary David Mundell said the verdict showed the legal challenge had been “the right thing” for the UK Government to do.

He said: “The Supreme Court has provided much-needed legal clarity that the Continuity Bill goes beyond the powers of the Scottish Parliament.

“This demonstrates clearly that it was the right thing for the UK Government to refer the Bill to the Court.”

He added: “It is now for the Scottish Government to consider how to proceed and we hope Holyrood will take a pragmatic approach and work constructively with us as we leave the EU.”

The Scottish Government’s top legal officer, Lord Advocate James Wolffe, will make a statement to MSPs later on the matter on Thursday afternoon.

The Attorney General and the Advocate General for Scotland, the UK Government’s senior law officers, had referred the Bill to the Supreme Court to seek legal certainty “in the public interest” .

They acted after SNP ministers in Edinburgh introduced their own legislation to counter the “power grab” in the UK’s European Withdrawal Act, which they claimed would see responsibilities going to London rather than Edinburgh after Brexit.

When the Bill was passed, Scottish Government ministers insisted it was within Holyrood’s competence – although the Scottish Parliament’s Presiding Officer, Ken Macintosh, ruled against them on this.

At a hearing in London in the summer, the court was asked to rule on whether the European Union (Legal Continuity) (Scotland Bill) which MSPs passed in March was constitutional and “properly within devolved legislative powers”.

Announcing the decision Supreme Court President Lady Hale said that one section of the Bill was outside the Scottish Parliament’s powers because it would have the effect of making UK law “conditional” upon the consent of Scottish Ministers.

She said the UK Parliament’s European Union (Withdrawal) Act “changes the legal landscape” and is “protected from modification”.

Lady Hale said this prevents the Scottish Bill from “amending, superseding, disapplying or repealing provisions of that Act”, and said therefore parts of it would be “outside the legislative competence” of Holyrood.