It was all meant to run on tramlines, a Nuremberg-style trial to show the world that dictators could be made to face justice in the land they once terrorised.

Twenty two months after being hauled from a hole in the ground, Saddam Hussein would finally answer for his crimes before a fully functioning Iraqi court.

The case seemed straightforward. The torture and execution of 148 Shia men and boys from Dujail after a failed assassination attempt against the former president in 1982 would never rank as the greatest of Saddam's crimes, but it was relatively easy to prove. A string of witnesses would appear in court, along with documents providing conclusive proof of Saddam's direct involvement.

The Bush administration hoped the hearings would expose the nature of Saddam's crimes that they had used, in part, to justify their invasion. They also expected a guilty verdict, and Saddam's resulting execution, would take the sting out of the Sunni insurgency. America spent more than $140m (£74m) preparing for the trial, fortifying the court and training Iraqi officials.

"We hoped it would set a new standard for justice, not just in Iraq but across the Middle East, showing citizens that their leaders could be held to account," a senior US legal advisor to the Iraqi tribunal said.

Saddam faced charges over the mass executions and torturing of Shia villagers, and with ordering the subsequent destruction of farmland in the area. Also charged were Taha Yassin Ramadan, a former vice president; Barzan Ibrahim al-Tikriti, Saddam's half-brother and a former head of the Mukhabarat; Awad Ahmad al-Bander, a former chief judge of Saddam's revolutionary court; and four Ba'ath party officials from Dujail.

Such was the confidence in the case that lawyers predicted it would be over in a month. There was an air of triumphant expectancy as Saddam and the seven co-accused were called one by one by the usher into court for the first session, shortly after midday on October 19 last year in the former Ba'ath party headquarters, now inside the Green Zone.

Whether by accident or by design, Saddam was the last to appear. Unlike the others, who wore traditional Arab robes, Saddam appeared rather dapper, wearing a dark off-the-peg pinstripe suit and open necked shirt, bought for him by his American jailers.

His grey-flecked beard was neatly trimmed and his dyed hair had been cut and combed. But the 68-year-old looked thinner than the last time he had been seen in public - at his arraignment - and the lines etched into his brow spoke of the strains of solitary confinement. He was however calm and self-assured, and spoke with the firmness that had characterised his years of autocratic rule.

Yet from the moment the senior judge on the five man panel asked him to stand and identify himself, Saddam brought the proceedings to the verge of anarchy, setting the tone for most of the next nine months.

"Those who fought in God's cause will be victorious..." he declared, clutching a copy of the Koran. "I am at the mercy of God, the most powerful."

The judge asked him again to identify himself.

"Who are you? What does this court want?" Saddam said. "I don't answer this so-called court, with all due respect, and I reserve my constitutional right as the president of the country of Iraq.

"I don't acknowledge either the entity that authorises you, nor the aggression, because everything based on falsehood is falsehood."

The judge then told Saddam to "relax" and said the court could hear his testimony later. But he still needed his name.

"You know me," came the response. "You are an Iraqi and you know that I don't get tired."

Despite refusing to recognise the legitimacy of the court, Saddam would later mutter that he was "not guilty", his plea echoed by his co-defendants.

"From the moment Saddam Hussein refused to tell the judge his name and recognise the legitimacy of the court, their strategy for the trial became clear," said the US legal advisor, who attended many of the sessions.

That strategy, according to Khalil al-Dulaimi, Saddam's chief defence lawyer, was to use the proceedings to stoke the insurgency and to keep the trial going for as long as possible, so that in the end a frustrated US would do a deal with Saddam to release him in return for his help in restoring order to the country.

"He'll be the last resort; they'll knock on his door," Mr Dulaimi told the New York Times. "The United States will use this sentence to pressure Saddam to save it from its mess."

Walkouts, boycotts and hunger strikes

Try as they might, the battalion of US and Iraqi legal experts could not insulate the trial they had organised from the violence and instability coursing through Iraq.

During the trial, three defence lawyers were killed and another fled abroad. More than 30 witnesses were too intimidated to come to court. Of those who did, many gave evidence from behind screens or had their voices disguised electronically.

The sessions were dogged by procedural wrangling and technical faults, and repeatedly disrupted by anti-American tirades, hunger strikes, and walkouts and boycotts from an obstreperous Saddam and his defence team, who frequently complained that they were not being given access to vital documents.

It seemed politics were at a maximum and legalities at a minimum. If the new Iraqi authorities hadn't intended a show trial, then the former leader and his co-defendants were intent on making it one.

Saddam the performer took his last chance to redeem himself in the eyes of his dwindling band of loyalists - ably supported by a cast of his former cronies. Barzan, his half-brother took, to wearing his pyjamas in court, sitting defiantly with his back to the judges. Tariq Aziz, Saddam's well- known former international envoy, delivered his courtroom encomium to his ex-boss in what appeared to be a hospital gown.

As the chaos spread, the international community rapidly lost confidence. The proceedings were repeatedly criticised by prominent human rights groups and bodies such as the UN, which described them as "incompatible" with standards of international justice.

The disruptive tactics meanwhile had Iraq's new leaders and US officials on edge. They weighed in from the sidelines, publicly criticising the judge for being too tolerant of the defence's antics, and urging a speeding up of the whole process.

Saddam judge: I did my job

The brunt of their ire, and of Saddam's truculence, was borne by the chief judge, Rizgar Mohammed Amin.

Speaking to the Guardian in his family home in Sulaymaniya last week, Judge Rizgar recalled the enormous pressures surrounding the trial - pressures that are thought to have eventually caused his resignation in January this year - although he declined to give the exact reasons why he left his post.

"I knew that everyone would be saying that it was an extraordinary and special situation, but I treated everything as if it were a normal case," said the judge. "I believe a judge should always be neutral. That neutrality gives me a profound strength to treat proceedings in a normal and professional manner."

As the trial progressed, the sniping increased. The prime minister, Nuri al-Maliki, said repeatedly that he favoured Saddam's swift execution. But Judge Rizgar remained unmoved.

"I did my job. Others are free to think what they want," he said. "According to law it is forbidden to talk in a way that will leave an impact on the judge or the prosecutor. But did we have full implementation of this law?"

He was subsequently replaced by another Kurdish judge, Rauf Abdel Rahman, whose instantly more assertive approach won praise from some Iraqis, but raised further questions about the court's impartiality.

Indeed, as the case proceeded, the unruliness and defiance from Saddam and his team worsened. Saddam would regularly denounce the US and Iraq's new rulers. At one point he told the judge to "go to hell" - and got away with it.

The trial's fairness was a vital concern in a nation that is trying to bring reconciliation between its Sunni Arab minority, which dominated Iraq under Saddam, and the Shia Muslim majority and its Kurdish partners who now control the government.

Iraqis enthralled by trial broadcast

Millions of Iraqis were glued to coverage of the trial, which was beamed live from the courtroom, albeit with a 20-minute time delay so that some of Saddam's outbursts could be censored.

And the effect of seeing the once absolute and infallible ruler of Iraq in the dock, quibbling with a judge, for a while at least held the nation in thrall - though the Shia and the Kurds were happier than the Sunni Arabs, some of whom saw the trial as a sign of their humiliation and marginalisation.

Amid the clamour, the harrowing witness accounts of torture and murder in Dujail at the hands of former Ba'athist officials were all but drowned out.

More than 80 Iraqis testified over 40 court sessions. Ahmed Hassan Mohammed was the first to take the stand. He gave a graphic account of torture at the hands of the Iraqi secret police.

He described how after the assassination attempt in Dujail, north of Baghdad, when Saddam's motorcade was attacked as it was passing through, women and children were tortured.

"People who were arrested were taken to prison and most of them were killed there. The scene was frightening. Even women with babies were arrested," Mr Mohammed said.

He alleged that the torture equipment included a mincing machine that was sometimes fed with living human bodies.

The prosecution also produced a wealth of documents from the previous regime, which they claimed proved Saddam's guilt.

As the trial drew to a close Saddam appeared to acknowledge that he had signed the death warrants for the men in Dujail, but said it was his constitutional right as a president, and that he had been defending Iraq from the Iranian-sponsored militants of the Dawa party who had organised the ambush on his motorcade.