(CNN) - The UK government's decision to shut down Parliament in the run-up to Brexit was illegal, Scotland's highest civil court has ruled, in a serious blow to embattled Prime Minister Boris Johnson.

In a devastating ruling, a panel of three senior judges unanimously declared that Johnson's advice to the Queen to suspend Parliament for five weeks was "unlawful."

Johnson has always insisted that his decision was a routine device that allowed the government to start a new parliamentary session with a fresh legislative agenda. But the Scottish judges disagreed, saying it was motivated by the "improper purpose of stymying Parliament."

"This was an egregious case of a clear failure to comply with generally accepted standards of behaviour of public authorities," ruled one of the judges, Lord Brodie, according to a summary of the decision posted online.

The court did not immediately issue an order to lift the suspension -- also known as prorogation -- noting that the High Court in London had come to a different conclusion and that the UK Supreme Court would need to resolve the issue. The government confirmed that it would appeal the Scottish court's decision to the Supreme Court.

Joanna Cherry, a member of Parliament for the Scottish National Party, who was the lead petitioner in the cross-party group of politicians which brought the action, said the decision was a "historic ruling."

Dominic Grieve, who was attorney general in the government of former Prime Minister Theresa May, said if it was established that Johnson had misled the Queen, he would have to resign."If that were to to be the case that this had happened, Boris Johnson would find himself in an untenable position in Parliament," he told the BBC.

Speaking to CNN, Labour MP Hillary Benn -- one of the lawmakers leading the charge to seize control of the Brexit process -- said Britain was "in a crisis" and called on the Prime Minister to recall Parliament.

"It's of huge constitutional significance," he said. "If they were to uphold, the Prime Minister will have to bring parliament back. Frankly, he should do it anyway. He should never have sent us away at a time of huge significance. We are in a crisis."

Johnson held a so-called "People's PMQs" on Facebook Live hours after the decision, but failed to directly refer to the ruling.

However, he did reject claims that he was anti-democratic, and said a Queen's Speech is needed to "push on" with his domestic agenda. "That's what the public, I think, want us to do."

Advice to the Queen ruled unlawful

In their unexpected ruling on Wednesday, the Scottish judges overturned an earlier decision that the courts did not have the power to interfere in the Prime Minister's political decision to prorogue parliament.

They found that the real reason for suspending Parliament -- to frustrate its role in holding the government to account -- was so significant that it justified a legal ruling.

In the summary of their ruling -- the full text of which will be published on Friday -- the judges were sharply critical of the government.

"It was to be inferred that the principal reasons for the prorogation were to prevent or impede Parliament holding the executive to account and legislating with regard to Brexit, and to allow the executive to pursue a policy of a no deal Brexit without further Parliamentary interference," Lord Brodie said.

The ruling concluded that the Prime Minister had acted illegally when he advised the Queen to suspend Parliament. "The Court will accordingly make an order declaring that the Prime Minister's advice to HM the Queen and the prorogation which followed thereon was unlawful and is thus null and of no effect," the summary concluded.

Lawyer Jolyon Maugham, part of the group which funded the Scottish legal action, said the ruling had a clear meaning: "We believe that the effect of the decision is that Parliament is no longer prorogued," he tweeted.

The UK government's reaction

In its response to the ruling, Downing Street confirmed it would appeal. "We are disappointed by today's decision, and will appeal to the UK Supreme Court," a spokesman said.

"The UK government needs to bring forward a strong domestic legislative agenda," it added. "Proroguing Parliament is the legal and necessary way of delivering this."

Opposition lawmakers demanded Parliament be recalled, while some returned to Parliament Wednesday to protest.

Keir Starmer, the Labour Party's Brexit spokesman, tweeted that he welcomed the court's decision: "No one in their right mind believed Boris Johnson's reason for shutting down Parliament."

Nicola Sturgeon, leader of the Scottish Nationalist Party, said the decision was of "huge constitutional significance" and added that Parliament "must be recalled immediately."

The Liberal Democrats' Brexit spokesman, Tom Brake, said the ruling was "highly embarrassing" for Johnson, and described the prorogation as a "power grab."

Nicholas Soames, the grandson of Britain's wartime leader Winston Churchill and one of 21 MPs expelled from the parliamentary Conservative party for voting against the government in a Brexit vote, said he did not regard suspending parliament as "constitutional outrage."

"I think they're losing sight [of] what matters, that we get a deal that enables Britain to leave the European Union in an orderly manner," he told CNN. "We are really in the end game now."

Suspending Parliament in order to restart the political calendar is usually a routine annual event, but the timing and length of this five-week prorogation was criticized because it limited opportunities for lawmakers to legislate against a potential no-deal Brexit, ahead of the October 31 deadline for the UK to leave the European Union.

Johnson's predecessor Theresa May had allowed the current parliamentary session to run far longer than normal because of the protracted nature of Brexit.

Johnson therefore argued that a suspension was needed to make way for a new Queen's Speech, setting out the government's legislative agenda.

The Prime Minister claimed that the prorogation had nothing to do with Brexit and that it was "nonsense" to suggest he was attempting to undermine democracy, while Jacob Rees-Mogg, Leader of the House of Commons, said the suspension was "completely constitutional and proper."

But Johnson's opponents claimed he was shutting down Parliament to stifle debate, and to allow the clock to run down on Brexit.

Challenges to Johnson's decision were filed in separate courts by a cross-party group of lawmakers and peers and the prominent anti-Brexit campaigner Gina Miller.

Lawmakers are not scheduled to return to parliament until October 14, just days before the UK is due to leave the EU.