The case was originally dismissed at the Court of Session last week, where Judge Lord Doherty said it was for politicians and not the courts to decide on shutting down the Commons and Lords for five weeks.
But three judges of the Inner House, the supreme civil court in Scotland, disagreed with that ruling today.
The UK government plans to appeal the latest ruling on Tuesday at the Supreme Court – the highest judicial body in the country – and has promised to respect the final result.
Senior politicians, including First Minister of Scotland Nicola Sturgeon and Labour’s shadow Brexit secretary Sir Keir Starmer, have urged for parliament to be recalled now.
A summary handed down today said: “This was an egregious case of a clear failure to comply with generally accepted standards of behaviour of public authorities.”
It added there were two “principal reasons” for Mr Johnson closing parliament – legally known as prorogation.
First to “prevent or impede parliament holding the executive to account and legislating with regard to Brexit”.
And second to “allow the executive to pursue a policy of a no-deal Brexit without further parliamentary interference”.
It said the suspension of parliament was “unlawful and is thus null and of no effect”.
A UK government spokesperson said they were “disappointed” at the decision and claimed suspending parliament was “the legal and necessary way” of delivering “a strong domestic legislative agenda”.
Government sources believe the court’s decision does not mean parliament is automatically recalled, since the order enforcing it will not be published before the Supreme Court showdown next week.
A Number 10 source was quoted by The Sun saying “the legal activists choose the Scottish courts for a reason”.
That prompted a swift rebuke from the justice secretary, who tweeted: “Our judges are renowned around the world for their excellence and impartiality and I have total confidence in their independence in every case.”
Joanna Cherry QC, one of 70 MPs behind the legal action, hailed the ruling as a “huge victory”.
She said: “We have uncovered more and more evidence that this was a plot by Boris Johnson and his cronies to prevent us from stopping them taking Scotland and the UK off a Brexit cliff edge by forcing through a damaging no-deal against the will of parliament.
“This ruling takes us one step closer to ensuring the UK government cancels their shameful prorogation and blatant plot to force through an extreme Brexit. Boris Johnson cannot be allowed to break the law with impunity.”
Sir Keir Starmer called for the prime minister to call MPs back to Westminster “immediately” to “decide what happens next”.
He told Sky News: “Across the country I don’t think many people actually believe the prime minister when he said this was just for a Queen’s Speech.
“But for a court to say that the documents really point one way and that they undermine his case to a point where they’ve ruled him unlawful, that’s an incredibly powerful thing for them to have done.”
“We need to be back in parliament doing our job, at the very least looking at this judgement and deciding collectively what should happen next.”
Nicola Sturgeon also tweeted that “parliament must be recalled immediately”.
Len McCluskey, general secretary of the Unite union, told Sky News: “My advice to the prime minister is don’t go up to Scotland, you’re liable to face a citizen’s arrest, so he’d best keep in his bunker somewhere in either Eton or Westminster.”
A spokesperson for Speaker John Bercow’s office said: “Any decision to accelerate the meeting of parliament during prorogation is a matter for the government.”
Some MPs have gathered in parliament to protest its suspension, at the time they would normally be gathering for Prime Minister’s Questions.
Also today, a court delivered its reasons for dismissing a separate legal challenge brought by Gina Miller, saying the decision to suspend parliament was “purely political” and therefore not up to the courts to rule on.
Mr Johnson has insisted he suspended parliament to follow procedure, which dictates the Commons and Lords are shut down in the run up to a new Queen’s Speech.
That marks the opening of a new parliamentary session, where the monarch reads out her government’s priorities for the year ahead, and is due to take place on 14 October.
But critics have accused him of hiding from scrutiny over Brexit and disempowering MPs at a time of national crisis with 50 days to go until Brexit.
Some tried to block the speaker leaving his chair when parliament was shut down in the early hours of Tuesday, while others held signs up saying “silenced”.