It's as dramatic a moment of constitutional law as you will see in your life. Lady Hale cut a calm, good-natured figure as she sat at the head of the Supreme Court. But the words she spoke boomed out like mini earthquakes. Each one devastated the government. By the time she was done, its moral status lay in ruins.

The first hurdle was justiciability - was the decision to suspend parliament through prorogation within the court's remit or was it fundamentally a political issue? This was the highest legal barrier those who brought the case faced, but it fell easily. The ruling, Hale said, was unanimous. "We are firmly of the opinion that it is justiciable."

The court then had to look at the legal substance. There were a couple of ways to go. They could look at the motive of the prime minister when he made the prorogation request of the Queen. Or they could look at the effect - that the prorogation denied parliament its role in scrutinising the government. It skipped the first and zeroed in on the second.

In doing so, it reminded us of some very basic constitutional lessons about how British democracy works. "We live in a representative democracy," Hale said. "The House of Commons exists because the people have elected its members. The government exists because it has the confidence of the House of Commons. It has no democratic legitimacy other than that."

Since the referendum, Tory governments - under first Theresa May and then Boris Johnson - have tried to lay claim to a new source of political authority: that of the Brexit vote. But this was simply a mandate for the principle of leaving the EU, not for the manner of doing so. Should it be soft, hard or no-deal Brexit, for instance? It offered no instruction on that. That required parliament. But the government had tried to silence it instead.

This is the tried-and-tested route of autocrats. They always claim to have some magical connection to the people which offers them legitimacy, while ignoring the structures which might actually demonstrate it. Today, the Supreme Court brought that farce to an end.

"The first question is whether the prime minister's action had the effect of frustrating or preventing the constitutional role of parliament in holding the government to account," Hale said. "The answer is that of course it did."

Just a few weeks ago, most legal commentators held out little hope of this challenge succeeding. But in a truly heroic effort, two figures - Gina Miller and Jolyon Maughn - ignored death threats and a constant stream of abuse to bring the case and stand up for the basic constitutional structure of the UK. It had worked its way up to the highest court in the land.

Even then the assessments were conservative. Very few people were expecting a unanimous verdict. And even if it went against the government, most thought it would offer No.10 some other way of proroguing, or demand that Johnson start a new session, which would have given him time to muck around preparing a new Queen's Speech and delay things. But in the end it was much stronger than that.

The advice on prorogation, Hale said, was unlawful. "It was outside the powers of the prime minister to give it. This means that it was null and of no effect. It led to the Order in Council which, being founded on unlawful advice, was likewise unlawful, null and of no effect and should be quashed. This led to the actual prorogation, which was as if the commissioners had walked into parliament with a blank piece of paper. It too was unlawful, null and of no effect."

And then came the body blow. "It follows that parliament has not been prorogued."

An hour later, Speaker John Bercow confirmed MPs would reconvene tomorrow at 11:30am.

It was completely fitting that Hale was so calm and good-natured when she delivered the judgement. That is the manner in which the British constitution is supposed to operate - on the basis of trust, high standards and a respect for the rule of law. It is that quality which allows it to be unwritten, because of its maturity and deeply-held cultural commitment to its own values.

The Johnson government has tried to break that arrangement to pieces. It has acted, under the authorship of Dominic Cummings, in a fundamentally untrustworthy way, without honour or respect for the rule of law. It has led to the insane degenerate spectacle of a prime minister unable to confirm that he would even obey the law.

In the face of that behaviour, the other pillars of the constitution had to step up. Parliament did its part. Using extraordinary constitutional innovations, it passed legislation to stop the prime minister forcing through no-deal a few weeks ago. And now the judiciary has done the same.

Some people have claimed that the case showed the need for a written constitution. There may or may not be good arguments for that, but they were not provided by today's events. The ruling showed that Britain's constitution worked. It may be mercurial, but that has the advantage of making it nimble. When the moment came to prevent an executive from running out of control, it did so.

This is Britain working, even under extreme strain and chaos.

But it is also something even more profound than that. It is the deep, system-level functioning of liberal democracy. This works by splintering power up, by sharing it out between governments and parliaments and courts and international bodies.

Brexit is presented as some sort of triumph of popular will. But in actuality it has involved a relentless attempt to massively strengthen the executive and dismiss other forms of democratic legitimacy, to an extent not seen in this country since the days of absolute monarchy.

But today the operating mechanics of liberal democracy fought back. It was a marvellous sight to behold.

Ian Dunt is editor of Politics.co.uk and the author of Brexit: What The Hell Happens Now?

The opinions in Politics.co.uk's Comment and Analysis section are those of the author and are no reflection of the views of the website or its owners.