IT seems apt that the last act in the long-running Carmichael election court drama should take you by surprise.

The ordinary position in law is that “expenses follow success”: the loser pays. But during its many twists and unexpected turns, the fate of this election petition has been anything but ordinary. Starting from a small, improbable place, it has been quite the saga. Expectations, upended. Outcomes, surprising everyone. New precedents – legal and political – set.

On the May 23 last year, in the aftermath of the General Election, a confession finally having been coaxed out of the former Secretary of State, I sat down to write what I thought would be a mischievous, hypothetical blog. “Is Carmichael vulnerable to an election petition?”, I asked. Having alighted on this little-known and little-understood corner of election law, I concluded that it might – just might – be worth a punt.

But I didn’t expect anyone to play Don Quixote, and to brave the costs and the uncertainties of litigation to put Carmichael in the witness box and this speculative legal theory to the test. Yesterday’s decision underscores the eye-watering scale of those costs. All in, it is estimated this case will have cost around £400,000 for a handful of court days. To put this figure in a bit of context, the average annual salary in Scotland is around £26,500 before tax. Election petitions are beyond the reach of most electors.

I say this as no criticism of the learned lawyers at the heart of this case, who have applied themselves diligently and professionally to this tricky matter. But whatever you make of the rights and wrongs of this case, whatever you think about courts being asked to rule on elections, the petitioners have achieved something remarkable and unprecedented. Their costs will be borne by their formidable – historically unprecedented – crowdfunding effort. Who will foot Carmichael’s now equally formidable legal bill remains unclear.

At first, pundits chortled. Unfamiliar with election law, many dismissed this case as madcap, doomed from the outset. Commentators were initially confident the petition would fall at the first legal hurdle. It did not. They imagined evidence would not be called for. Lady Paton and Lord Matthews had different ideas. They figured Mr Carmichael would not be forced to take the stand and face cross-examination. But the Northern Isles MP endured several uncomfortable hours in the witness box. This case has brought surprise after legal surprise. Even the Liberal Democrat’s near-death survival was a shocker – not least to himself – his political career preserved by the narrowest of legal margins.

Even as a psychodrama, it has been a charged tale. The four petitioners, fairly anonymous ordinary folk, risking much in the pursuit of a point of principle.

Judges, holding the fate of all five in their hands, struggling to make sense of this tricky and unfamiliar branch of law. Often making heavy weather of his part asAs the flawed and bungling anti-hero at its centre, Alistair Carmichael has played a man wounded, a man ill-treated, a man persecuted and wronged. Grousing, embittered and unrepentant, throughout this case he has seemed like a soul harried in his own person. He grins a politician’s grin into the cameras, but the light never quite reaches the eyes.

In the witness box, he was Carmichael the reluctant witness. In the judges’ verdict, he was Carmichael the “unimpressive”, Carmichael the “blatant” liar, Carmichael “at best disingenuous, at worst evasive and self-serving.” In his own mind, however, you get the impression that none of this has really touched the former Secretary of State. Only this might explain his ill-judged rush in front of the TV cameras, to trumpet victim fantasies and vindication, before reading the fine and damning detail of the election court’s judgment.

And the aftermath? Public consciousness about election petitions has never been higher this century. Candidates in this year’s Holyrood election would be well-advised to learn the lessons of Carmichael. And as for the Northern Isles MP himself? As this case ends, he creeps away, poorer, diminished, shabby, and in victory, defeated.

Alistair Carmichael faces legal bill up of to £150,000 for 'Frenchgate' case

Orkney Four who took Carmichael to court: ‘It’s sad that we had to go this far’

The National View: The law must be changed so politicians can be held to account