LIKE the central character in the spoof western, Support Your Local Sheriff, Joel Joffe was on his way to Australia when events swept him up.
In the summer of 1963, Mr Joffe was a young lawyer in Johannesburg planning to leave and set up a new life in Australia. He was suffocating in the oppressive, brutalised and brutalising environment created by apartheid but he was not politicised by it. He just wanted out with his family.
As he wound up his practice, Mr Joffe was dimly aware that on 11 July 1963 seven men were arrested at Lilisleaf Farm in the Johannesburg suburb of Rivonia. They included secretary general of the ANC Walter Sisulu, Govan Mbeki, Raymond Mhlaba and Dennis Goldberg.
The South African security services thought they had captured the effective leadership of the ANC and its recently established military wing, Umkhonto we Sizwe.
With the death penalty in force, and frequently used, the South African state planned a trial that would lead to the decapitation of the ANC and would convince the white population that apartheid could overcome any challenges to it. There was a ripple of arrests following the Rivonia raid, and attempts at flight by ANC members who knew the knock at the door was close. By the time the indictment for the Rivonia trial was complete, the list of accused included Nelson Mandela, who was already in jail at the time, and Jimmy Kantor, a partner in Joel Joffe's legal practice.
Mr Joffe was approached to ask if he would represent the accused in the trial. He agreed, and the preparation for the trial and the courtroom proceedings became his life until the verdict was delivered 10 months later.
He wrote an account of the trial process immediately afterwards but declined to publish it until the accused were free in 1990. It was published first in South Africa and an updated edition, The State v Nelson Mandela: The Trial that Changed South Africa was published by One World Books in 2007.
Mr Joffe will be speaking about his recollections of the Rivonia Trial at the Edinburgh International Book Festival on Wednesday.
His tale is far more than an account of a courtroom drama, albeit in a significant case. It is an extremely readable description of the legislative lawlessness that characterised apartheid.
All the accused and most of the prosecution witnesses were held under 90 day detention powers. This meant the defence team were hardly able to see the men they were supposed to be representing while the prosecution witnesses clearly had spelled out to them the consequences of giving the wrong evidence.
Even during the trial, the government passed further laws that might be applied retrospectively and could have added offences to the indictment.
The first indictment lodged by the prosecution was legally incoherent and was actually thrown out by the judge. The replacement was little better but allowed by judge Quartus de Wet, who was also indulgent of the prosecution's haphazard approach to proving evidence.
Mr Joffe also explains the conceptual problems for the defence team, caught between the prosecution's crude conduct and the collective decision of the accused not to deny any parts of the prosecution case that were true about their leadership role in attempting to overturn the regime.
It was even a matter of lengthy debate among them, in the full knowledge that the death penalty would probably follow conviction, whether they should even plead not guilty. That may have seemed like weakness to their supporters and the movement.
In the end they decided pleading not guilty would allow them to speak and state clearly that they considered it was the apartheid state that was on trial.
Mr Joffe says: "They felt from the outset that, because of their standing in their movement and in the country, it was not only their right but also their obligation to go into the witness box and explain precisely what they had been aiming to do and why."
The self-imposed limits on their evidence were that they would deny nothing about their role, but refuse to answer questions that might implicate others.
In particular, they wanted to explain that Umkhonto we Sizwe had, as a matter of agreed strategy, to focus attacks against government buildings and installations where no loss of life could be involved. They acknowledged that the time might well come when it would have to turn to more militant struggle and guerrilla warfare. But that time had never been reached.
If the accused were admitting most of the offences on the indictment on political grounds, it left the defence little room for manoeuvre and the objective became, principally, to head off the death sentence.
The accused also advised the defence team that if they were sentenced to death they would not appeal.
When it came to his turn to give evidence, Mandela, Accused Number 1 on the indictment, refused to be cross examined but instead delivered his memorable words in a five-hour statement from the dock.
Mandela concluded: "During my lifetime I have dedicated myself to the struggle of the African people. I have fought against white domination, and I have fought against black domination. I have cherished the ideal of a democratic and free society in which all persons live together in harmony and with equal opportunities."
At this moment he paused, a long pause, in which one could hear a pin drop in the court, and then looking squarely at the judge he finished: "It is an ideal which I hope to live for and to achieve". Then dropping his voice, very low, he added: "But if needs be, it is an ideal for which I am prepared to die".
The verdicts are well known. Mandela and his co-accused spent close to 30 years in jail before their walk to freedom.
Mr Joffe of course never made it to Australia. Instead, he emigrated to the UK, where he is now a member of the House of Lords and a former chairman of Oxfam.
But how did his part in the Rivonia trial change his life? "It allowed me to meet and for a time work with some of the most remarkable men of the 20th century," he says. "But it also settled for me that injustice always has to be challenged. It diminishes everyone if you walk away."
• Joel Joffe will appear at the Edinburgh International Book Festival on 19 August at 8pm. www.edbookfest.co.uk