Ahmed Kathrada in 1989, arriving home following his release from prison, where he served 26 years for his opposition to South Africa’s racially discriminatory system of apartheid. (Walter Dhladhla/AFP via Getty Images)

Ahmed Kathrada, an anti-apartheid activist who spent 26 years in prison with Nelson Mandela and later served as a leader and a voice of conscience of the African National Congress, died March 28 at a hospital in Johannesburg. He was 87.

His nonprofit organization, the Ahmed Kathrada Foundation, announced his death. He had recently undergone surgery to remove a blood clot in his brain.

The son of Indian immigrants, Mr. Kathrada dropped out of school as a teenager in the 1940s to devote himself to the liberation struggle — first for South Africa’s marginalized Indian population, and then, joining forces with Mandela, for the country as a whole.

The two met in the mid-1940s, shortly before the white-supremacist National Party began formalizing rules that dictated where black Africans, mixed-race “coloreds,” whites and “Asians” such as Mr. Kathrada could live or work.

“When Mandela was starting out, he wasn’t very interested in allying with people of other races because he felt it was an African struggle,” Stephen Clingman, a professor at the University of Massachusetts at Amherst, said in an interview. Mandela’s views changed, he said, in part by seeing people such as Mr. Kathrada risk jail time or worse for acts of civil disobedience.

Mr. Kathrada leads President Barack Obama on a tour of Robben Island, a former prison, in 2013. (Madelene Cronje/Mail and Guard/European Pressphoto Agency)

Beginning with his arrest for protesting the “Ghetto Act” of 1946, which restricted the rights of Indians to own land, Mr. Kathrada was at or near the center of seemingly every major anti-apartheid action of the era, including the 1952 Defiance Campaign that he helped organize with Mandela and other leaders of the ANC and its Indian counterpart, the South African Indian Congress.

After 69 black protesters were shot by police officers in the northern city of Sharpeville in 1960, the ANC, outlawed and branded a terrorist organization, responded by launching a wave of bombings directed at government property.

On July 11, 1963, Mr. Kathrada and about a dozen other ANC leaders were swept up in a police raid on the organization’s secret headquarters, a farmhouse in the Johannesburg suburb of Rivonia, and charged with 221 acts of sabotage for conspiring to “ferment violent revolution.”

The trial riveted the nation, in part because of a three-hour courtroom speech by Mandela, who was already in prison but faced new charges linked to alleged ANC bomb plans found at the Rivonia farmhouse. He called for “a democratic and free society in which all people will live together in harmony . . . an ideal for which I am prepared to die.”

Instead of receiving death sentences, Mandela, Mr. Kathrada, ANC deputy Walter Sisulu and six others were sentenced to life in prison.

Mr. Kathrada spent 18 years at Robben Island, an Alcatraz-like compound off the coast of Cape Town, and eight more at nearby Pollsmoor Prison. Robben, he told the NPR program “Here & Now” in 2013, “was a microcosm of apartheid as it existed outside.” Performing forced labor at a limestone quarry on the island for about a decade, he was granted an outfit of long pants and socks. Black inmates such as Mandela were allowed to wear only short pants, and even in the winter were forced to work without socks.

Despite the hardship, Mr. Kathrada used his prison time as a political training ground, discussing organizing techniques with Sisulu, with whom he shared a cell for several years, and helping Mandela draft and then smuggle his memoirs to the outside world. Supported by money from his family, Mr. Kathrada also completed four bachelor’s degrees in history and African politics.

President Nelson Mandela talks to Mr. Kathrada before an address to parliament in 1999. (Reuters)

The prison was also a place of relative safety, he told the New York Times in 2013. Unlike on the mainland, he said, “no policeman could come to Robben Island and start shooting at us. . . . Others, people we knew closely, [were] tortured to death, shot, assassinated. We were safe.”

Mr. Kathrada was released in 1989, after negotiations that resulted in the official recognition of the ANC and the country’s first open elections. Mr. Kathrada was elected to South Africa’s Parliament in 1994 and served five years as parliamentary counselor to Mandela, who was elected president.

He expressed little bitterness about his prison sentence, or about apartheid more generally, and later became a sort of diplomatic tour guide on Robben Island, showing foreign dignitaries his cell at the prison.

“Anger, revenge are negative emotions,” he told NPR this year. “If one harbors those emotions, you suffer more. And that is where our very progressive policy of forgiveness [came from], in which the ANC started with the transformation from apartheid to democracy — forgive. Don’t harbor hatred and revenge.”

Ahmed Mohamed Kathrada was born in Schweizer-Reneke, a northern farming community, on Aug. 21, 1929. His father was a shopkeeper.

Unable to attend local schools because of racial restrictions, he studied in Johannesburg, 200 miles to the east and quickly immersed himself in politics, joining the Young Communist League at 12.

Mr. Kathrada said he experienced a turning point of sorts when he visited the Auschwitz concentration camp in 1951. He collected a small amount of bones — a reminder, he later said, “of the evils of racism which dominates every aspect of South African life.”

Survivors include his wife, Barbara Hogan, a fellow political prisoner who served in the cabinets of Kgalema Motlanthe and his successor, President Jacob Zuma. Mr. Kathrada called for Zuma’s resignation last year, amid a corruption scandal in which the president was found to have used public money for renovations on his country home.

A statement from Zuma’s office described Mr. Kathrada as a “stalwart of the liberation struggle for a free and democratic South Africa.”