In theory I should now be dead. Not from disease or an accident but because of the simple fact that my head was set to be severed from my body with a sharp sword in a public square in Riyadh, the Saudi Arabian capital.

In 2001, I was condemned to die in this brutal archaic fashion after being caught up in what became known as the "Saudi Brits" affair. Along with eight others, I was rounded up by the panicked Saudi authorities after a series of attacks on foreigners in the kingdom suddenly started to make this expat country of choice seem distinctly unsafe.

Desperate to pin a nascent anti-government insurgency on squabbling "bootlegger" foreigners (anything rather than concede that ultra-safe Saudi Arabia had an internal terrorism problem), we were to be the sacrificial lambs. Remember those bizarre, wooden "confessions", haltingly delivered by scared looking men on national Saudi television? One of those came from me. If I looked petrified it may have been because I'd been dragged to prison, threatened, sleep-deprived and beaten so severely that I almost died from heart attacks.

In a numbed state of shock, I would have confessed to anything. As it was, I said I'd committed a series of laughably implausible "turf war" crimes that never even existed. The farce continued. I was subjected to two perfunctory, completely scripted trials at which I was told to plead guilty and beg for mercy. I was sentenced to death, tried again twice without even being in the courtroom at all, and again sentenced to death by beheading.

This, remember, is what happened just a handful of years ago in a justice system of an influential Middle Eastern country that enjoys excellent diplomatic relations with most of the world's powerful countries, including Britain. It was only this time last year, for example, that we were rolling out the red carpet for King Abdullah's state visit.

So, how did I come to be alive to write this for the Guardian today? Simple. Belonging to a wealthy "client" nation like the United Kingdom means that while you can be tortured and falsely imprisoned in Saudi Arabia, in practice you are not going to suffer a brutal demise in "chop chop" square in this execution-addicted country.

At the time of my ordeal there was much talk of "diplomatic efforts" to secure our release. This was mostly UK government spin – they had to put it about that they were trying hard to get us out. Yes, they will have exerted pressure on the Riyadh authorities but I later learnt that I and my fellow detainees had been released as part of a "prisoner exchange" involving five Saudis being held by the US at Guantánamo Bay.

Finally released in August 2003, after 964 days of solitary confinement, torture and dehumanising terror, I harbour no illusions about what saved me: my passport. There was no apology, no official pardon, just a perfunctory granting of "clemency" and immediate expulsion from the country. An accident of birth had preserved me and eventually my release became a political expediency.

Ironically, even the manner of my release further confirmed the politically corrupt nature of the Saudi system of justice. Foreign workers like me, subject to bogus trials and languishing in miserable jails, can only hope that the Saudi lottery of false mercy will save them. Meanwhile, of course, Saudi's poor migrant workers from Somalia, Bangladesh, the Philippines or Pakistan are virtually doomed if they face a capital charge (not all for lethal crimes, incidentally).

Anyone who might somehow think that Saudi justice is harsh but fair should read a new Amnesty International report (pdf) which shows that the legal system is heavily rigged, with well-connected Saudi nationals up to eight times more likely to negotiate "blood money" pay-offs to victims' families that lead to commutation.

Certainly one shouldn't forget that ordinary Saudis without the right connections are also going to their deaths in this lethal lottery of a justice system. The latest figures show that this blood-soaked country is on average executing at least two people every single week.

In my experience what passes for a judicial system in Saudi Arabia has less to do with investigating crime and punishing criminals, and far more to do with maintaining control and compliance among both its own citizens and its community of ex-patriot workers.

Why should we care? Well, apart from the fact that thousands of British people go to work in this country every year and that Britain continues to maintain extremely cordial relations with the Saudi royals, this wretched system is simply an affront, not only to justice but to our common humanity.

If ever there was an advertisement for the abolition of the death penalty and for all that is wrong with its application, Saudi (in)justice provides it.

I can only ask: when are western governments going to stop pandering to the Saudi princes? Or could it be that they prefer to go on burying their heads in the sand?