The case was brought to try to compel Johnson to comply with legislation requiring him to ask Brussels for more time if no agreement was reached before the end-of-month Brexit deadline
Anti-Brexit campaigners on Monday failed to secure a court ruling forcing Prime Minister Boris Johnson to seek an extension if no deal is reached about Britain's departure from the European Union.
The case was brought to try to compel Johnson to comply with legislation requiring him to ask Brussels for more time if no agreement was reached before the end-of-month Brexit deadline.
But judge Lord Pentland told Scotland's highest civil court, the Court of Session in Edinburgh, the government had already made "unequivocal assurances" it would abide by the law.
There was "no doubt" Johnson and the government accepted the need to comply and they intended to do so, the judge said in his ruling.
"I am not persuaded that it is necessary for the court to grant the orders sought or any variant of them," he added.
Johnson has repeatedly said he will take Britain out of the EU by October 31 come what may, despite a law requiring him to write for an extension in the event of a no-deal.
Campaigners said his public stance and submissions to the court were contradictory, raising fears among Brexit opponents the government could use a loophole to get around the law.
The judge warned that Johnson's failure to comply could damage the "mutual trust" between the courts and the politicians.
Johnson has already suffered a legal setback after Britain's Supreme Court unanimously ruled that the prime minister had unlawfully suspended parliament to stifle Brexit debate.
One of those who brought the case in Edinburgh, lawyer Jolyon Maugham, said he hoped the court's confidence in the government's assurances were right.
But he remained unconvinced and promised to launch an appeal.