Image copyright PA

The UK government has launched a legal challenge to the Scottish and Welsh governments' Brexit bills.

The two devolved parliaments passed legislation last month that is intended to act as an alternative to Westminster's EU Withdrawal Bill.

But the UK government has asked the Supreme Court to rule whether the legislation is constitutional and within devolved powers.

Holyrood's presiding officer has already said he does not believe it is.

But Lord Advocate James Wolffe, the Scottish government's top legal advisor, argues the bill is competent, and recently took the unusual step of making an address to MSPs on this point.

He said the bill was "carefully framed so that it does not do anything or enable anything to be done, while the UK remains a member of the EU", and that it was "modelled, in this regard, on the UK government's EU Withdrawal Bill".

Elin Jones, the presiding officer of the Senedd, has also ruled that AMs could pass the legislation under their existing powers.

The UK government's senior law officers, the Attorney General and the Advocate General for Scotland, have now confirmed they have asked the Supreme Court to rule on the issue.

Lord Keen, the Advocate General for Scotland, said: "By referring the Scottish Parliament's Continuity Bill to the Supreme Court, we are seeking legal certainty as to its competence.

"Given the presiding officer's view at introduction that the bill was not within the legal scope of the parliament, we believe it is important to ask the court to provide absolute clarity.

"In doing so we are following the process set out in the Scotland Act 1998. Particularly in the run up to Brexit, it is vital that we avoid legal uncertainty in our statute book."

What do the devolved administration say?

The Scottish government's Brexit secretary, Michael Russell, said its EU continuity bill had been "overwhelmingly" passed by 95 votes to 32 in the Holyrood chamber - with only the Conservatives opposed.

He added: "Scottish Ministers are satisfied that the bill is within legislative competence.

"The Lord Advocate will be arguing in the Supreme Court that it is within the powers of the Scottish Parliament to prepare for the consequences for devolved matters of UK withdrawal from the European Union."

The Welsh government's finance secretary, Mark Drakeford, said it would also defend its bill "to the full".

Analysis by Philip Sim, BBC Scotland political reporter

This legal action seeks to untangle a series of legislative strands which have sprouted from the Brexit process in London, Edinburgh and Cardiff.

First off, there's Westminster's EU Withdrawal Bill, opposed by the Scottish and Welsh governments.

Then there's the Scottish Parliament bill, opposed by the presiding officer but defended by the Lord Advocate.

Then there's the National Assembly for Wales bill, which is backed by its presiding officer.

Both of those have now been opposed by UK legal officers, who say the devolved bills risk "creating serious legal uncertainty".

Who is right? The Lord Advocate, the Attorney General, the Scottish Presiding Officer, the Welsh Presiding Officer? MPs, MSPs or AMs? Tasked with sorting through this jumble of competences will be the justices of the Supreme Court.

Well, probably. There's still a chance that political, rather than legal, agreement can be found over the Westminster bill that started all this - and then there would be no need for any court action at all.

However, we've been saying that for quite a few months now with no sign of a deal, and the two sides are getting rather dug in. This is one aspect of the Brexit divorce which could well end up in court.

Ministers in Edinburgh and Cardiff are at loggerheads with those in Whitehall over how UK-wide frameworks of powers which are currently exercised from Brussels should be overseen.

Both sides agree these frameworks should be set up, but UK ministers want to have final oversight over some key areas in the short term - something the devolved administrations term a "power grab".

They want their consent to be formally sought over the running of these frameworks, while UK ministers have offered only to "consult" them.

The UK government has pledged to amend the EU Withdrawal Bill to settle the row, but with no sign of an agreement on the wording of this change, the devolved administrations brought forward their own legislation to act as a stop-gap should they ultimately not give consent to the Westminster bill.