ITV’s election debate between Boris Johnson and Jeremy Corbyn will go ahead on Tuesday evening as scheduled after the Liberal Democrats and Scottish National party failed to convince the high court in London that their party leaders – Jo Swinson and Nicola Sturgeon – should be included.

After hearing legal arguments all day, two senior judges, Lord Justice Davis and Mr Justice Warby, ruled that because the broadcasting company was not exercising “a public function” it was not liable to judicial review challenge in the courts.

The only remedy for the Liberal Democrats and the SNP, the judges said, was to complain to the broadcasting watchdog, Ofcom. The court had earlier heard that Ofcom cannot deal with complaints about programmes until after they have been aired.

Delivering judgment Lord Justice Davis said: “The decision to schedule tomorrow’s debate in this format was a matter for the editorial judgment of ITV, which cannot be said to have displayed a want of due impartiality for the purposes of the broadcasting code: especially in the light of subsequent planned interviews, further debate and other programmes, which are properly to be regarded as a series of linked programmes. No arguable breach of the broadcasting code is shown.”

He added: “The editorial judgment was, in public law terms, a judgment properly and reasonably open to ITV. It did not take into account irrelevant or immaterial factors; and the decision cannot be regarded as irrational or perverse.”

The TV debate on Tuesday can therefore “lawfully go ahead”, Lord Justice Davis concluded. A fuller version of the judges’ reasoning will be published at a later date. They refused permission to appeal.

Lawyers for the Liberal Democrats and the Scottish National party had gone to the high court to argue that it was illegal and unfair to restrict the main debate programme to only the Conservative and Labour party leaders while excluding any political voice for anti-Brexit remain supporters.

Lawyers agreed there was a gap in the powers of Ofcom, the broadcasting watchdog, which prevents it from banning programmes in advance of broadcast. ITV is subject to Ofcom’s code, which includes a duty to preserve impartiality and to give due weight to an appropriately wide range of significant views.

ITV’s proposed format of the main party leaders’ debate with only Conservative and Labour politicians breached that code, counsel for the Liberal Democrats and the SNP told the court. Guy Vassall-Adams QC, representing the Liberal Democrats, had argued: “The general election has only come about because of Brexit. The dominant issue of this election is Brexit. A number of opinion polls have consistently recorded Brexit as the most significant question.

“[But] there will be no one in the debate who represents remain. The voice of remain has been excluded.”

The Liberal Democrats have also sent a letter to the BBC objecting to a similar decision by the corporation for a programme it will host on 6 December.

Philip Coppel QC, for the SNP, said that lodging a complaint with Ofcom after the debate would be a useless remedy. “The harm to the SNP or Liberal Democrats will be irreversible. It will be cold comfort that some time after the general election, [the parties] receive a document upholding a complaint,” he said.

Broadcasting a separate interview programme with leaders of the other parties, including the Liberal Democrats and SNP, later on Tuesday evening – after an edition of I’m a Celebrity … Get Me Out of Here! – would not redress the political imbalance, he said. “Two of the most important issues of this election are Brexit and Scottish independence,” Coppel added.

Opening ITV’s defence of the format for its Tuesday evening election programmes, Kieron Beale QC said that it had “given due weight to questions of impartiality”. He said that ITV did not accept that it was exercising the role of a public body. “Brexit is just one issue in this campaign among a number of others,” he stated. “Both Labour and the Liberal Democrats publicly support a second referendum. This is a UK-wide election and therefore [the main leaders’ debate] was between those trying to obtain majority control.”

Ian Blackford, the SNP’s leader at Westminster, said afterwards: “This election is a chance for people in Scotland to vote to escape Brexit, to protect the NHS and to choose their own future with independence – yet they will not hear that argument in the debate tomorrow night.

“Instead, they will only hear from the leaders of two parties who both want to pursue Brexit – taking Scotland out of the EU against its will.”

He added: “What is now clear is that the UK broadcasting system is similarly incapable. Indeed the result of the decision to exclude the SNP is to discriminate against Scottish voters and to effectively treat them as second-class citizens.”