Boris Johnson’s suspension of the UK Parliament is unlawful, Scotland’s highest civil court has ruled.
A panel of three judges at the Court of Session found in favour of a cross-party group of politicians who were challenging the prime minister's move.
The judges said the PM was attempting to prevent Parliament holding the government to account ahead of Brexit.
A UK government appeal against the ruling will be heard by the Supreme Court in London next week.
The Court of Session decision overturns an earlier ruling from the court, which said last week that Mr Johnson had not broken the law.
The current five-week suspension of Parliament, a process known as proroguing, started in the early hours of Tuesday.
MPs are not scheduled to return to Parliament until 14 October, when there will be a Queen's Speech outlining Mr Johnson's legislative plans. The UK is due to leave the EU on 31 October.
Opposition parties have called for Parliament to be immediately recalled in the wake of the court judgement, but Downing Street said this would not happen ahead of the Supreme Court's ruling on the case.
Downing Street also distanced itself from reports that quoted Number 10 sources as suggesting the Scottish judges were politically biased, and insisted that the prime minister has "absolute respect" for the independence of the judiciary.
What did the Scottish judges say?
Mr Johnson had previously insisted that it was normal practice for a new government to prorogue Parliament, and that it was "nonsense" to suggest he was attempting to undermine democracy.
But the Court of Session judges were unanimous in finding that Mr Johnson was motivated by the "improper purpose of stymieing Parliament", and he had effectively misled the Queen in advising her to suspend Parliament.
They added: "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 group of more than 70 largely pro-Remain MPs and peers behind the legal challenge were headed by SNP MP Joanna Cherry, who said they felt "utterly vindicated".
The parliamentarians appealed to the Inner House of the Court of Session after their original challenge to the suspension of Parliament was dismissed by judge Lord Doherty last week.
Lord Doherty said Mr Johnson had not broken the law by proroguing Parliament, and that it was for MPs and the electorate to judge the prime minister's actions rather than the courts.
But the three Inner House judges said they disagreed with Lord Doherty's ruling because this particular prorogation had been a "tactic to frustrate Parliament" rather than a legitimate use of the power.
One of the three judges, Lord Brodie, said: "This was an egregious case of a clear failure to comply with generally accepted standards of behaviour of public authorities.
"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 Drummond Young said that the UK government had failed to show a valid reason for the prorogation, adding: "The circumstances, particularly the length of the prorogation, showed that the purpose was to prevent such scrutiny.
"The only inference that could be drawn was that the UK government and the prime minister wished to restrict Parliament."
The High Court in London says that advice given by the prime minister to the Queen to suspend parliament is basically "political" - something the government has argued from the get go - and so it's not a matter the courts should get involved in because there are really no legal standards against which to judge it.
Scotland's highest court disagreed, strongly.
It ruled that the prime minister's advice could be unlawful if its purpose was to stymie parliamentary scrutiny. That's because parliament's role in scrutinising the government is a central pillar of our constitution, which follows naturally from the principles of democracy and the rule of law.
Two courts, two totally contradictory judgments.
They are now both hurtling towards the highest court in the land, the UK Supreme Court, where that contradiction will be resolved. There will be a definitive ruling on whether the prime minister acted unlawfully, or not - and that will determine whether parliament is to be recalled in the lead up to 31 October.
And that is how our constitution works. Through what's known as judicial review, independent judges can stop the might of government in its tracks if what ministers have done is unlawful. Because as lawyers like to say: "Be you ever so mighty, the law is above you."
What was the reaction to the ruling?
A spokesman for Number 10 said it was "disappointed" by the decision, and would appeal to the Supreme Court.
He added: "The UK government needs to bring forward a strong domestic legislative agenda. Proroguing Parliament is the legal and necessary way of delivering this."
Scotland's first minister, Nicola Sturgeon, said the ruling was of "enormous constitutional significance", and that Parliament should be recalled immediately to allow it to do the "real and substantive work of scrutiny".
She added: "The prime minister's behaviour has been outrageous and reckless, and has shown a complete disregard for constitutional rules and norms."
Labour's Shadow Brexit secretary Sir Keir Starmer said Parliament should be recalled as early as this afternoon.
He told the BBC: "Most people didn't believe Boris Johnson, but for the courts to find he has unlawfully shut down Parliament and that his motive wasn't the one he said it was? That's very powerful.
"I call on him to recall Parliament. Let's get it back open, and sitting this afternoon and tomorrow, so we can debate what happens next and we can debate this judgement."
Liberal Democrat leader Jo Swinson, who was one of the politicians involved in the case, said: "There is one reason why Boris Johnson has prorogued Parliament and that's because he wants to force through his no-deal Brexit, and he wants to do that without having scrutiny and without having to abide by the normal rules."
And Dominic Grieve, the former Conservative MP and attorney general who now sits as an independent, said the prime minister should "resign very swiftly" if he has misled the Queen.
The Court of Session does not criticise the Queen's decision to prorogue Parliament at Boris Johnson's request; it rules on the advice the prime minister gave the Queen. But the ruling raises questions for the Palace and the constitutional role of the Queen.
Although the Queen was expected to grant the prorogation - there was precedent for suspending Parliament before the Queen's Speech, and she acts on the advice of her ministers - she is not simply a rubber stamp for the government of the day.
How well was the Queen advised? Should the Palace have pushed Downing Street harder as to the reasons for the prorogation? The Queen has been drawn into the Brexit mire, and the questions now go to the heart of her constitutional role.
If she has no discretion at all over prorogation, what is her constitutional purpose? If she has discretion, when would she use it? Traditionally politicians step very carefully around these issues so as not embarrass the Queen and upset the constitutional order. But these are far from traditional times.
What happened at the High Court in London?
High Court judges in London have given their reasons why a similar legal challenge by businesswoman Gina Miller was dismissed last week.
They said they rejected her claim because the suspension of Parliament was a "purely political" move and was therefore "not a matter for the courts".
Lord Chief Justice Lord Burnett, Master of the Rolls Sir Terence Etherton and President of the Queen's Bench Division Dame Victoria Sharp said their conclusion was based on "well-established and conventional grounds".
They said the speed with which Parliament passed a bill to prevent a no-deal Brexit highlighted a flaw in Ms Miller's argument.
"The ability of Parliament to move with speed when it chooses to do so undermines the underlying premise of the case for the claimant that prorogation would deny Parliament the opportunity to do precisely what it has now done," the judges said.
Ms Miller is appealing the decision in the Supreme Court at the hearing which will take place on 17 September.
What questions do you have about the latest Brexit developments?
Use this form to ask your question:
If you are reading this page on the BBC News app, you will need to visit the mobile version of the BBC website to submit your question on this topic.