Andrew Mlangeni, the last surviving co-defendant convicted in 1964 with Nelson Mandela at the Rivonia Trial, which focused a global spotlight on the segregationist policies of apartheid in his native South Africa and helped define the battle lines for an epochal struggle against white minority rule, has died at a military hospital in Pretoria. He was 95.

His death was confirmed by the office of President Cyril Ramaphosa, which said on Wednesday that he had died overnight after being admitted to the hospital because of an abdominal complaint.

All eight men accused of sabotage at the trial were given life sentences and served long prison terms. Mr. Mandela’s was the longest, 27 years behind bars, until his release in 1990 as South Africa began a remarkable transformation to fully democratic elections in 1994.

Mr. Mlangeni served 26 years as Prisoner 467/64 (Mandela was 466/64), incarcerated for much of the time on Robben Island; he was released in 1989. Unlike the charismatic Mr. Mandela, who became South Africa’s first Black president, Mr. Mlangeni cast himself in a far more self-effacing role.

An official biography, written for his charitable foundation in 2017, was entitled “The Backroom Boy,” a reference to his clandestine activities in the underground world of resistance and, perhaps, to the language of apartheid, when white bosses routinely referred to adult Black underlings as “boy.”

When Mr. Mlangeni arrived under heavy guard on Robben Island in 1964, he and other Black convicts in the group were issued prison uniforms with short trousers usually reserved for schoolchildren and menial Black workers such as gardeners.

For all his reticence, though, Mr. Mlangeni was part of a historic vanguard as opponents of apartheid turned to violent tactics, starting in December 1961, with the creation of a secretive insurgent group called uMkhonto weSizwe, the Spear of the Nation.

According to Mr. Mlangeni’s biography, Mr. Mandela sought him out and selected him to join five other men in the first group of South African anti-apartheid activists to be sent for training to China. (Mr. Mlangeni had to prove his physical fitness by performing push-ups to Mr. Mandela’s satisfaction, according to this account.)

Faced at home with powerful, white-led security forces and an all-pervasive secret police, the would-be freedom fighters played a cat-and-mouse game to avoid detection as they planned their journey to China as representatives of the outlawed African National Congress and South African Communist Party.

Outside South Africa, the activists relied on a network of exiles to arrange passage for Mr. Mlangeni and the rest of the group, who slipped out of their own country to neighboring Botswana, then called the Bechuanaland Protectorate, and traveled through Tanzania, Sudan, Ghana, Zurich, Prague, Moscow and Irkutsk, in Siberia, before reaching China, according to a series of interviews in 2019 with a prominent South African journalist Pippa Green.

During their training, the South Africans said later, they were amazed to be visited by Chairman Mao Zedong — the head of the Chinese Communist Party — and other leaders, including his deputy, Deng Xiaoping, and Premier Zhou Enlai.

Mao “looked me straight in the face and I did the same, trying to be as great a soldier as I could,” Mr. Mlangeni said, according to his biography.

Their training comprised schooling in the techniques of secret communications, bomb-making, booby traps and the Maoist philosophy of insurgency. But their ability to put their lessons into practice turned out to be short-lived.

After he returned to South Africa in late 1962, Mr. Mlangeni became a member of the insurgents’ high command. He disguised himself as a priest with the nom de guerre the Rev. Mokete Mokoena and traveled around South Africa recruiting young people to go abroad for training as insurgents. But in June 1963, he broke the rules of his tradecraft by staying at his home in the Dube section of Soweto rather than in a safe house. The police raided it.

They were subsequently accused of sabotage along with others who had been arrested at a farmhouse in the Rivonia District of Johannesburg’s northern suburbs to face charges of plotting to overthrow the state with a campaign of sabotage that could have brought the death sentence.

The subsequent trial, named for the Rivonia area and beginning in 1963, drew broad international attention and is often remembered for a stirring address from the dock in which Mr. Mandela evinced his readiness “if needs be” to sacrifice his life for the cause of freedom.

But Mr. Mlangeni also spoke, urging Judge Quartus de Wet to “remember what we, African and nonwhite people, have had to suffer. That is all I have to say except to add what I did was not for myself but for my people.”ImageSeveral A.N.C. leaders, including Mr. Mlangeni, center, at the Holy Cross Church in Soweto, South Africa, after their release in 1989.Credit…Patrick Durand/Sygma, via Getty Images

Andrew Moeti Mokete Mlangeni was born on June 6, 1925, on a remote, white-owned farm near the town of Bethlehem, around 150 miles south of Johannesburg. He was the ninth child of 10 born to Aletta and Matia Mlangeni, a farm laborer who died when Andrew Mlangeni was 6. Mr. Mlangeni had a twin sister Emma. When he was imprisoned, she died of cancer weeks before his release in 1989. The authorities refused to allow him to attend her funeral.

In later life, Mr. Mlangeni said he had been born in a township near Johannesburg, but this was a ruse to thwart a police practice of sending people they considered troublemakers back to their place of birth.

By all accounts, he started school only at the age of 11 or 12, after the family moved from the Bethlehem area to nearby Kroonstad, although his father had taught him to read. He worked informally as a caddy for the exclusively white players at a golf course in Bethlehem. The game inspired him with such enthusiasm that he was playing into his 90s.

In 1945, Mr. Mlangeni joined the Young Communist League, one of several groups opposed to apartheid. The League was organized in cells along revolutionary lines. His cell leader was Ruth First, a white communist and anti-apartheid activist killed in 1982 by a parcel bomb mailed by the South African security police while she was in exile in Mozambique.

In 1950, Mr. Mlangeni married June Ledwaba, whom he met while she was working as a shop assistant in Soweto. She, too, was an anti-apartheid protester, harassed by the security police while her husband was incarcerated.

The 1950s were a time of ferment and ever greater repression, when the African National Congress, the South African Communist Party and other groups like the breakaway Pan Africanist Congress struggled both against the apartheid authorities and to define the narrative of resistance.

For Mr. Mlangeni, the ideological debate culminated in the adoption in 1955 of the Freedom Charter, setting out a vision of a nonracial South Africa in which the nation’s wealth would be redistributed. Mr. Mlangeni called it the “bible that would be used to pursue freedoms for all South Africans.”

The authorities’ response took the form of the Treason Trial from 1956 to 1961, when more than 150 anti-apartheid defendants, including Mr. Mandela but not Mr. Mlangeni, were all acquitted.

In 1960, the newly formed Pan Africanist Congress had organized a demonstration in Sharpeville, around 40 miles south of Johannesburg, when the police opened fire on unarmed protesters and killed 69.

The massacre spurred a huge crackdown by the authorities in which the principle anti-apartheid movements were outlawed under a state of emergency.

By the time the Rivonia trial ended in June 1964, it was clear that the authorities were bent on crushing and silencing the leadership of resistance. Once imprisoned, Mr. Mandela became an invisible figurehead in waves of protest that ultimately led to the formal dismantling of apartheid in the early 1990s.

Mr. Mlangeni became a lawmaker in 1994 in the newly created multiracial Parliament but retired after a single, five-year term.

He continued to exert significant influence as head of an A.N.C. committee charged with maintain the party’s integrity and, according to his interviews in 2019, frequently urged President Jacob Zuma, his former comrade-in-arms, to resign as president in the face of sweeping corruption charges still grinding their way through the courts in 2020. Mr. Zuma was finally forced from office in 2018.

But Mr. Mlangeni always resisted the notion that he might be a figure of public influence.

“I was never at the forefront of the A.N.C.,” he said in a 2013 documentary of the years before his imprisonment “I was always a backroom boy.”

Mr. Mlangeni is survived by his two daughters, Maureen and Sylvia, and a son, Sello. His wife died of cancer in 2001, shortly after their 50th wedding anniversary, and his eldest son, Aubrey, in 1998.