Image copyright Getty Images Image caption The bill would give AMs some powers currently handled by Brussels

The UK Government has confirmed that it will refer the Welsh Government's Brexit law to the highest court in the country.

Judges in the Supreme Court will decide if the Continuity Bill can become law.

It was passed by AMs in March to hand Welsh ministers EU powers in devolved areas after Brexit.

Welsh Secretary Alun Cairns has said the action was aimed at giving legal clarity. The Welsh Government said it would defend its bill.

Finance Secretary Mark Drakeford said the Welsh Government would defend its bill "to the full".

Discussions are ongoing between the two governments about what happens to powers in devolved areas after the UK leaves the European Union.

Mr Cairns said he was "optimistic" agreement would be reached on the return from Brussels of 64 powers in devolved areas.

Under the latest proposal from the UK Government, the vast majority of those devolved powers in areas such as agriculture support and food labelling will go to Cardiff, Edinburgh and Belfast after Brexit whilst the rest will be held temporarily in London.

But the Welsh and Scottish governments have said those proposals amount to a "power-grab" and that UK-wide frameworks should be agreed by consensus.

What is going on?

Image caption The Supreme Court is the UK's highest court

Analysis by James Williams, BBC Wales Brexit correspondent

For the fourth time, Welsh and UK government lawyers are headed to the Supreme Court.

Why? Well, although under devolution the Welsh Assembly has been given powers by the UK Parliament to operate in certain areas, there are plenty of blurred edges, and in this case the judges will decide whether Welsh ministers and AMs have overstepped the mark with the Continuity Bill.

Even the Assembly's Presiding Officer says it is touch and go.

But it may not even come to that.

It is important to remember there are two potential pieces of Brexit law in play here; the Continuity Bill that was pushed through the Assembly in double-quick time as an insurance policy against the UK Government's EU Withdrawal Bill, which has almost finished its journey through the Houses of Parliament in Westminster.

Discussions between the UK, Welsh and Scottish governments over changes to the Withdrawal Bill continue with all sides hopeful that agreement can be reached.

If so - and it remains a big if given those discussions have been ongoing for several months - then Welsh ministers will withdraw their Continuity Bill so there'll be no need for a day in court.

As already noted, the Continuity Bill is ultimately an insurance policy - one the Welsh Government, even at this late stage of the process, hopes it won't have to cash in.

Image caption The legislation was been introduced in the assembly under a quicker timetable than usual

Attorney General Jeremy Wright said: "This legislation risks creating serious legal uncertainty for individuals and businesses as we leave the EU.

"This reference is a protective measure which we are taking in the public interest. The government very much hopes this issue will be resolved without the need to continue with this litigation."

The Welsh Government said it would defend "any action before the Supreme Court".

Its spokeswoman said: "We have always said our preference is for a UK-wide Withdrawal Bill, which respects devolution and we continue to work with the UK Government to achieve this.

"In the meantime, our bill is a legitimate means of protecting Welsh interests and devolution settlement."'

'Drastic'

Welsh Conservative Leader Andrew RT Davies said he did not think the Welsh Labour Government had "adopted the right approach", taking issue with the speed at which the bill was put through the assembly.

"I think stage 2 was completed within 40 minutes and stage 3 most probably a little shorter time than that," he said.

But Mr Davies added that he was "very pleased" with the progress made in the discussions between the UK, Welsh and Scottish government on changes to the EU Withdrawal Bill.

Plaid Cymru AM Bethan Sayed said: "We believe that it's quite drastic for the UK Government to go to the Supreme Court just to verify the process.

"They're using light words but it seems quite an extreme action to take in this regard.

"It does create a mockery of joint working to take it to this level. If it's not a power grab, why take us to court?"