As the instructing solicitor for Nelson Mandela’s defence team at the Rivonia trial of 1963-64, Joel Joffe, later Lord Joffe, who has died aged 85, played a key role in helping the future South African president and others avoid the death penalty. That was the severest sentence that could have resulted from being convicted of sabotage, and Mandela described Joffe as “the general behind the scenes in our defence”.

Charges followed a police raid in July 1963 on Liliesleaf Farm in the Johannesburg suburb of Rivonia, where Mandela and his anti-apartheid co-conspirators – including Govan Mbeki, Walter Sisulu, Lionel “Rusty” Bernstein, Andrew Mlangeni, Ahmed Kathrada and Dennis Goldberg – had been plotting the overthrow of the government. Mandela was already in jail for another offence and was indicted later.

At the time, Joffe, dispirited by the all-pervading power of apartheid, was winding down his business affairs in advance of emigrating to Australia. But when he was asked by Hilda Bernstein to defend her husband, and by Mandela’s then wife, Winnie, to defend him, he put his emigration plans on hold and threw himself into the case, which came to the supreme court in Pretoria the following October.

As Mandela was set on seizing the moral high ground and wanted the trial to inspire further resistance to apartheid, the strategy of the legal team, headed by the barrister and covert communist Bram Fischer, rested on trying to at least prevent the imposition of the death penalty. Initially Mandela had wanted to announce in his statement from the dock in April 1964 that he was prepared to die for his belief in a non-racial and democratic South Africa. However, Joffe, recognising Mandela’s great potential as a statesman of the future, tried to dissuade him from such a course of action. “I could not bear the thought of Mandela being hanged and decided that on the re-typed version I would leave out the ‘prepared to die’ sentence,” he said.

The next day he received a note from Mandela asking for the sentence to be restored, but with the addition of the words “if needs be” – a qualification that may have been crucial to the defendants’ survival. Joffe later learned that the lawyer George Bizos and Mandela’s eventual biographer Anthony Sampson had spent the previous evening persuading Mandela to agree to it.

Joel Joffe speaking at the Memories of Mandela event at the British Museum in January 2017

After the trial, Joffe visited Mandela in jail on Robben Island and was told that there would be no appeal. With the case over and his profile raised immeasurably, he and his wife – Vanetta Pretorius, an artist, whom he had married in 1962 – had won the admiration of black South Africans but had a more mixed reception among white ones. In 1965 he resurrected his plans to settle in Australia, but when that country refused him access as an “undesirable”, due mainly to his involvement with the Rivonia trial, he and Vanetta headed to the UK to make their new home.

Shortly after his arrival there Joffe teamed up with a colleague from his student days in Johannesburg, Mark Weinberg, and served as a director of Abbey Life Assurance (1965-70). With Sydney Lipworth, they transformed this into Hambro Life Assurance, later Allied Dunbar. The venture prospered, and during his two decades with it Joffe helped set up the charitable Allied Dunbar Trust, a pioneering corporate giving initiative which in particular supported projects to combat mental illness. He also became a leading philanthropist for UK-registered South African causes.

Joel was born in Johannesburg to Jewish immigrant parents who had met and married in South Africa. His father, Abraham Joffe, a businessman, had come from Latvia and his mother, Dena (nee Idelson), from what was then known as Palestine. After a Catholic boarding school, the Marist Brothers college, Joel studied law at the University of the Witwatersrand in Johannesburg, qualified as a solicitor in 1956 and six years later was called to the South African bar.

While working for a commercial law firm he built up a legal aid practice without the partners knowing, and when they objected to his pro bono work he moved to the more radical practice run by Harold Wolpe and his brother-in-law James Kantor. Wolpe was arrested shortly after the Rivonia raid, but escaped before he could be brought to trial and fled to Britain. The police then picked up Kantor under the same 90-day detention law. This meant that the two lawyers who could have been best placed to defend those arrested at Rivonia had been taken out of circulation – which is why Joffe was approached.

His book The Rivonia Trial (1995) was republished as The State vs Nelson Mandela: The Trial that Changed South Africa (2007). In January this year he gave a riveting account of what happened in the courtroom in a Memories of Mandela event at the British Museum that I chaired.

He served Oxfam in various capacities from 1980 to 2001, with two spells as chairman. Appointed CBE in 1999, he was a guest on BBC Radio 4’s Desert Island Discs in 2007.

After he was made a life peer in 2000, he tabled a private member’s bill in 2002 that sought to allow people to be given medical help to die under certain circumstances. The bill failed, but he re-introduced it in the Lords on several occasions. While it gained plenty of support in the public arena and stirred vigorous debate, it was never passed into law. He retired from the Lords in 2015.

He is survived by Vanetta and their three daughters, Lisa, Abigail and Deborah, and five grandchildren.

• Joel Goodman Joffe, Lord Joffe, lawyer and businessman, born 12 May 1932; died 18 June 2017