The United Kingdom supreme court has ruled that Boris Johnson’s advice to Queen Elizabeth that parliament should be prorogued for five weeks at the height of the Brexit crisis was unlawful.

The unanimous judgment from 11 justices on the UK’s highest court followed an emergency three-day hearing last week that exposed fundamental legal differences over interpreting the country’s unwritten constitution.

The momentous decision was read out by Lady Hale, president of the supreme court. Unusually, none of the parties were provided with advance copies of the judgment due to its sensitivity. Only seven of the 11 justices who heard the case were present in court.

The first legal question the judges had to resolve was whether the prime minister’s decision – exploiting residual, royal prerogative powers – was “justiciable” and could consequently be subjected to scrutiny by the courts. The English high court declined to intervene; the Scottish appeal court concluded that judges did have legal authority to act. The supreme court supported the Scottish interpretation.

Delivering judgment, Hale said: “The question arises in circumstances which have never arisen before and are unlikely to arise again.”

Then, giving the court’s judgment on whether the decision to suspend parliament was legal, Hale said: “This court has . . . concluded that the prime minister’s advice to her majesty [to suspend parliament] was unlawful, void and of no effect. This means that the order in council to which it led was also unlawful, void and of no effect should be quashed.

“This means that when the royal commissioners walked into the House of Lords [to prorogue parliament] it was as if they walked in with a blank sheet of paper. The prorogation was also void and of no effect. Parliament has not been prorogued.”

The decision to advise Her Majesty to prorogue parliament was unlawful because it had the effect of frustrating or preventing the ability of parliament to carry out its constitutional functions without reasonable justification.

Hale continued: “It is for parliament, and in particular the Speaker and the Lord Speaker, to decide what to do next. Unless there is some parliamentary rule of which we are unaware, they can take immediate steps to enable each house to meet as soon as possible. It is not clear to us that any step is needed from the prime minister, but if it is, the court is pleased that his counsel have told the court that he will take all necessary steps to comply with the terms of any declaration made by this court.”

She added: “The court is bound to conclude, therefore, that the decision to advise Her Majesty to prorogue parliament was unlawful because it had the effect of frustrating or preventing the ability of parliament to carry out its constitutional functions without reasonable justification.”

The judgment said: “This was not a normal prorogation in the run-up to a Queen’s speech. It prevented parliament from carrying out its constitutional role for five out of a possible eight weeks between the end of the summer recess and exit day on October 31st.

“Parliament might have decided to go into recess for the party conferences during some of that period but, given the extraordinary situation in which the United Kingdom finds itself, its members might have thought that parliamentary scrutiny of government activity in the run-up to exit day was more important and declined to do so, or at least they might have curtailed the normal conference season recess because of that.

“Even if they had agreed to go into recess for the usual three-week period, they would still have been able to perform their function of holding the government to account. Prorogation means that they cannot do that.”

The court stopped short of declaring that the advice given by Johnson to the queen was improper. It was a question. they said, they did not need to address since they had already found the effect of the prorogation was itself unlawful.

Dozens of remain supporters who had been waiting in the rain outside the supreme court since early morning erupted into cheers as news of the ruling filtered through.

The Scottish National party’s Joanna Cherry, a barrister who was among those who challenged the prorogation in Edinburgh, was first out to give her reaction. “There is nothing to stop us, myself and my colleagues, immediately resuming the important job of scrutinising this Tory government, which has us hurtling towards Brexit,” she said. “Boris Johnson must have guts for once, and resign.”

Gina Miller reacts outside the supreme court in London, where judges ruled that UK prime minister Boris Johnson’s advice to the Queen to suspend Parliament for five weeks was unlawful. Photograph: Jonathan Brady/PA

Gina Miller, who had taken the case to the supreme court, then emerged, flanked by lawyers and others.“Today is not a win for any individual or court,” she said, reading a prepared statement. “It’s a win for parliamentary sovereignty. The prime minister must open the doors of parliament tomorrow,” she added.

There were jeers and booing from a handful of far-right activists from the For Britain Party, who chanted “traitor” as the SNP parliamentary leader, Ian Blackford, gave interviews nearby. “We love you Boris, we do,” they sang.

Speculation before the ruling was that the court would find against the prime minister; that they were unanimous came as a surprise.