While it is the prime minister’s decision to suspend Parliament, the measure is formally carried out by the queen. In this case, the Scottish court said Mr. Johnson’s advice to the queen asking her to suspend Parliament was unlawful. The court said it would make an order declaring that the advice, and the suspension itself, was “thus null and of no effect.”

It was not clear when that order would be made.

Scottish law is different from the law in England and Wales, including on constitutional matters, scholars said on Wednesday, one reason the rulings in Scotland and in London may have conflicted.

But the government angered Scots when some unidentified Downing Street officials hinted to British news outlets that the rulings differed because the Scottish judges were politically biased. Robert Buckland, the government’s secretary of state for justice, quickly contradicted those claims, saying “our judges are renowned around the world for their excellence and impartiality.”

The team that brought the case said it had done so in Scotland because English high courts were not sitting in August.

The parliamentary shutdown began on Tuesday in raucous scenes, with opposition lawmakers throwing themselves at the speaker’s chair to keep him from standing up and allowing the chamber to be closed.

Parliament was not scheduled to sit again until mid-October, only weeks before Britain could crash out of the European Union without a deal.

When Mr. Johnson announced the suspension two weeks ago, it seemed likely to curtail the time that lawmakers had to stop him from pursuing a no-deal Brexit, an outcome that could create food and medicine shortages. But the shutdown quickly became a liability: It united a fractious opposition and emboldened lawmakers from his own Conservative Party to defy him on major votes.