Image copyright PA Media Image caption Jo Maugham QC led the action at the Court of Session in Edinburgh

Scotland's highest civil court has dismissed a legal bid to stop the UK government from passing its proposed EU withdrawal agreement.

Anti-Brexit campaigners had argued the deal contravened legislation preventing Northern Ireland from forming part of a separate customs territory.

However, Lord Pentland ruled the application was "misconceived and unjustified".

Campaigner Jo Maugham QC said the case was now unlikely to proceed further.

In his written opinion, the judge described the petition "of very doubtful competency" and concluded the petitioner had at best a "weak" case.

Image caption Lord Pentland issued his decision on Friday afternoon

Mr Maugham had lodged the petition on Thursday in an attempt to stop Parliament from passing the EU withdrawal agreement.

After the ruling was published he tweeted: "That was a difficult decision to make. It is difficult to move quickly and accurately and, the court has found, I got that decision wrong.

"We will review the decision carefully but my instinct is that we are unlikely to proceed to a full hearing for reasons indicated above."

He launched the legal challenge after the prime minister and European Commission President Jean-Claude Juncker announced on Thursday that the two sides had come to an agreement on a Brexit withdrawal deal, ahead of a crucial EU summit in Brussels.

EU leaders then approved the deal, and MPs are expected to vote on it on Saturday.

Image caption Aidan O'Neill QC is representing Mr Maugham in the case

Earlier Aidan O'Neill QC, acting for the petitioner, told the court that the proposed Brexit deal would mean a "continuing regime of EU law applicable to Northern Ireland" - contrary to Section 55 of the Taxation (Cross-Border Trade) Act 2018.

He said this would breach the Act's terms by creating different customs rules in Northern Ireland to the rest of the UK, leaving the deal void and unsuitable to be put before Parliament.

Mr O'Neill said: "The agreement which was presented yesterday is void; is of no effect as a matter of law."

Image copyright Getty Images Image caption Prime Minister Boris Johnson and European Commission President Jean Claude Juncker leave their joint press conference on Thursday

Government lawyers defended the deal and claimed the legal action was a "direct and manifest interference with Parliament".

Gerry Moynihan QC, acting for the government, described the legal challenge as "a gross intrusion into the separation of power."

He argued Northern Ireland would remain in the UK's customs territory because "a substantial part" of trade would still be with the UK.