Lord Pentland, sitting in the Outer House of the Court of Session in Edinburgh, threw out a petition that potentially threatened Mr Johnson with fines and imprisonment if he refused to follow the so-called Benn Act.
The act requires him to seek a delay to Brexit if he has not secured parliamentary approval for a withdrawal agreement or a no-deal departure by October 19.
The decision, which is expected to be immediately appealed to the Court of Session’s higher Inner House, came after the UK government issued an assurance, revealed on Friday, that it would abide by the act.
Mr Johnson has repeatedly said he would refuse to ask for an extension and continued at the weekend to insist the UK would leave the bloc on October 31, without agreement if necessary.
In his decision, Lord Pentland said there could be “no doubt that [Mr Johnson] now accepts that he must comply with the requirements of the 2019 [Benn] Act and has affirmed that he intends to do so”.
“The court should not pronounce coercive orders . . . unless it has been established on the basis of cogent evidence that it is truly necessary for such orders to be granted,” he wrote.
In Monday’s decision, Lord Pentland said statements in which Mr Johnson had said he would refuse to follow what he has called a “surrender act” were “expressions of the government’s political policy”.
“They were clearly not intended to be taken as conclusive statements of the government’s understanding of its legal obligations,” the judge wrote.
Aileen McHarg, professor of public law at Durham university, said the ruling was “a technical loss for the petitioners . . . but a de facto win”.
“They forced the government to give assurances that it will comply with the Benn Act,” Prof McHarg tweeted.