Roelof "Pik" Botha, right, greets Archbishop Desmond Tutu in 1997. (Odd Andersen/AFP/Getty Images)

Roelof “Pik” Botha, who spent decades at the center of South Africa’s political and diplomatic life as the last foreign minister under apartheid rule and who later served in the cabinet of the country’s first black president, Nelson Mandela, died Oct. 12 at a hospital in Pretoria. He was 86.

The cause was heart disease, his family announced.

Mr. Botha joined South Africa’s Foreign Service at 21 and held top diplomatic assignments, including simultaneous appointments in the 1970s as ambassador to the United Nations and to the United States.

He occupied an ambivalent place in South African public life, seen by some as a moderate voice in a brutal government and by others as a wily political survivor who was the public face and voice of a racist system clinging to power.

“He was way ahead of his political base in the Afrikaner political establishment” in his moderate views and skepticism toward apartheid, Chester A. Crocker, a U.S. diplomat who worked on South Africa’s transition to majority-black rule, said in an interview. “He was an unforgettable, stunning performer. He was a very colorful guy at the negotiating table.”

As early as the 1970s, Mr. Botha had publicly admitted that South Africa’s race-based apartheid policies were unjust and caused hardship, yet he also defended the white regime as it became an international pariah.

Botha in 1991. (Liu Heung Shing/AP)

In 1974, shortly before South Africa was expelled from the U.N. General Assembly, Mr. Botha pleaded for his country in a speech to the U.N.’s Security Council.

“Black Africans need not conduct a freedom struggle against my government,” he said. “Being an African country, we understand African aspirations. We have stolen land from nobody. We have conquered no people. We threaten no one.”

Mr. Botha first served in South Africa’s Parliament as a member of the National Party in 1970 and was often seen as a future prime minister, the country’s highest political office at the time. But his comparatively moderate views were increasingly out of step with the conservatism of the party’s white Afrikaner base. Some were suspicious of his cosmopolitan ways and openly speculated that he might have been a communist sympathizer or Soviet spy.

At diplomatic receptions, Mr. Botha reportedly said, “Nobody would talk to us, and nobody would talk to the Russians, so we ended up always having to talk to each other.”

He became foreign minister in 1977, a year after the Soweto student uprising, in which at least 176 protesters were killed by police. Oppressive measures were enacted against the country’s restive black majority, which made up about 70 percent of South Africa’s population. International sanctions were tightened, leaving South Africa’s white government more and more isolated.

“War has been declared on us,” Mr. Botha said in response. “We are not retreating.”

Alternately charming and hardfisted, Mr. Botha had a “Don’t Tread on Me” flag in his office. He charged the United States — with its checkered racial history — with “moral hypocrisy” in its dealings toward South Africa.

“Let the United States achieve complete equality before pontificating to me from a high moral forum,” he said.

In 1978, Mr. Botha was passed over in a bid for prime minister in favor of hard-liner P.W. Botha, to whom he was unrelated. By the mid-1980s, Pik Botha had become the cabinet’s most vocal advocate for reform.

“I cannot understand,” he said in 1987, while the restrictive practices of apartheid were still in place, “how you can stand in a lift with a black man with a toolbox in his hand, but when he puts on a suit, you want nothing to do with him.”

In the mid-1980s, Mr. Botha said that he could envision South Africa with a black president and that it was time for the government to release Mandela, the leader of the outlawed African National Congress party, who had been held as a political prisoner since 1962.

Right-wing opponents denounced Mr. Botha, shouting at rallies, “Pik, you are digging the white grave!”

In 1989, P.W. Botha resigned as prime minister and was replaced by F.W. de Klerk, who later assumed the new office of president. Pik Botha stayed on as foreign minister during a transitional period in which South Africa’s apartheid policies were dismantled.

Mandela was released in 1990 and was elected president four years later. Mr. Botha served in Mandela’s cabinet as energy minister until retiring from public life in 1996.

In a 2013 BBC interview, he marveled at Mandela’s resilient ability “to have left prison after so many years without bitterness. I so often experienced his capacity to forgive and his will to improve the country. . . . Historically, he played a role of a savior.”

Roelof Frederik Botha was born April 27, 1932, in Rustenburg, South Africa. His father was a high school principal.

Because of his youthful penchant for dressing in a suit and tie, Mr. Botha acquired the nickname “Pik,” a diminutive of the Afrikaans word for penguin.

After graduating from the University of Pretoria, he entered the diplomatic service. He had early assignments in Sweden and Germany and joined South Africa’s delegation to the United Nations in 1966.

He helped negotiate the settlement of conflicts throughout Africa, including a cease-fire between rebels and the government of Mozambique in 1984. He played a key role in the transition of the neighboring country of Zimbabwe (formerly Rhodesia) from white rule to a majority-black government. He also helped resolve the decades-long dispute over South West Africa, a territory under the authority of South Africa that gained independence in 1990 and became Namibia.

In 1997, Mr. Botha was the first top official of the National Party to testify before South Africa’s Truth and Reconciliation Commission, led by Nobel Peace Prize laureate Desmond Tutu. Mr. Botha asked for “God’s forgiveness” for failing to prevent the barbarity of the apartheid era.

His wife of 43 years, the former Helena Bosman, died in 1996. In addition to their four children, survivors include his wife since 1998, Ina Joubert.

During the 1970s, the South African government routinely banned journalists from the country, including Washington Post foreign correspondent Jim Hoagland. In 1976, Mr. Botha helped arrange for Hoagland to return to note “the positive change in race relations” in the country.

Hoagland wrote a multipart series condemning South Africa’s racial policies, leading to his permanent expulsion from the country.

“I later learned,” Hoagland wrote in an email, “that Pik had fully expected that I would continue to be critical of apartheid and had thought it would be helpful for the cause of change.”