Peter Magubane, a Black South African photographer whose images documenting the cruelties and violence of apartheid drew global acclaim but punishment at home, including beatings, imprisonment and 586 consecutive days of solitary confinement, died on Monday. He was 91.

His death was confirmed by family members speaking to South African television news broadcasts. No other details were provided.

Such were the challenges and perils facing Black photographers in South Africa’s apartheid-era segregated townships, Mr. Magubane liked to say, that he took to hiding his camera in hollowed-out bread loaves, empty milk cartons or even the Bible, enabling him to shoot pictures clandestinely.

“I did not want to leave the country to find another life,” he told The Guardian in 2015. “I was going to stay and fight with my camera as my gun. I did not want to kill anyone, though. I wanted to kill apartheid.”

He never staged pictures, or asked for permission to photograph people, he said. “I apologize afterwards if someone feels insulted,” he said, “but I want the picture.”

And he learned early in his career to put his photography first. “I no longer get shocked,” he once said, “I am a feelingless beast while taking photographs. It is only after I complete my assignment that I think of the dangers that surrounded me, the tragedies that befell my people.”

The country’s violence took its toll on him in 1992 when his son Charles, also a photographer and then in his early 30s, was murdered in the sprawling Black township of Soweto. Mr. Magubane (pronounced mah-goo-BAHN-eh) blamed migrant Zulu hostel-dwellers for the killing.

“I’ve been covering violence from the ’50s to now,” he said. “It’s never struck me as it’s struck me now. Now it has struck on my own door.”

He produced images of many of South Africa’s turning points, including the shooting deaths of 69 unarmed demonstrators in Sharpeville in 1960, the Rivonia trial of Nelson Mandela and other leaders of the African National Congress in the early 1960s, and the uprising by high school students in Soweto in 1976. But, when asked by The Guardian in 2015 to single out his best photograph, he chose a more tranquil image.

The photograph, from 1956, shows an anonymous Black maid in a beret and apron tending a young white girl on a bench marked with the words “Europeans Only.”

It is a poignant representation of an era and a symbol of the racial divide that the maid seems to be trying to reach across while her white charge peers inscrutably at the camera.

“When I saw ‘Europeans Only,’ I knew I would have to approach with caution,” Mr. Magubane told The Guardian. “But I didn’t have a long lens, so I had to get close. I did not interact with the woman or the child, though. I never ask for permission when taking photos. I have worked amid massacres, with hundreds of people being killed around me, and you can’t ask for permission.”

In that same period, he befriended Nelson Mandela and Mr. Mandela’s wife at the time, Winnie Madikizela-Mandela. After Mr. Mandela’s release from 27 years imprisonment in 1990, Mr. Magubane became his official photographer for four years, until Mr. Mandela’s election as South Africa’s first Black president in 1994.

Mr. Magubane has often been lionized among a generation of Black photographers whose skin color gave them access to the segregated townships but stirred visceral reactions among white police officers.

These photographers included Alf Khumalo and Sam Nzima, whose picture of Hector Pieterson, a fallen student in the 1976 Soweto riots, became one of the most potent images of the revolt and of the racial conflict that fueled it.

Much of the impetus for the advance of Black photography came from a magazine called Drum, which chronicled apartheid’s abuses, and its German-born chief photographer, Jürgen Schadeberg. Mr. Magubane was so eager to join the magazine that he took a job as a driver and messenger in 1954 before talking his way into the photography department.

Increasingly he cast himself as part of the campaign to end white minority rule.

After many brushes with the authorities, including five years under a so-called banning order, which denied him the right to work or even be photographed or quoted, Mr. Magubane went into the Soweto riots “with my camera and a vengeance,” he said.

“Because of my photos, the entire world saw what was happening,” he said.

When he arrived in Soweto on that day, June 16, 1976, young protesters “would not allow us to take pictures of them,” he told a university audience in South Africa in 2014.

He added: “I told them that, ‘Listen, this is a struggle; a struggle without documentation is not a struggle. Let them capture this, let them take pictures of your struggle; then you have won.’”

He believed that whatever his role as a photographer, it did not preclude intervention to save lives.

Testifying before South Africa’s Truth and Reconciliation Commission in 1996, he said that on June 16 in Soweto, a crowd was trying to pull a man from his car. “I quickly stopped taking pictures and went over there and said, ‘This will not help your cause at all,’” he said. “Fortunately this crowd did listen; they listened to me, and this man was able to drive where he was driving to.”

He also recounted an incident involving a “notorious” green car from which two white police officers opened fire.

“Wherever they shot, if there was someone that needed assistance I would become an ambulance-man, pick up the body, take it to the hospital if the person is still alive,” Mr. Magubane told the commission.

“Sometimes my colleagues wanted to know from me whether was it right for me to assist because my work is to photograph,” he continued, “and I said if my editor ever said to me I should not help — I should not give help when it is necessary — then my editor can go to hell.”

Peter Magubane was born on Jan. 18, 1932, in the mixed-race area of Johannesburg known as Vrededorp. He grew up in Sophiatown, a cosmopolitan suburb that was later zoned for exclusive white occupation and renamed Triomf, the Afrikaans word for triumph.

His father, Isaac, who sold vegetables to white customers from a horse-drawn cart, was a “tall, slender man with ‘colored’ features who spoke the oppressors’ language, Afrikaans,” Mr. Magubane wrote in an essay in 1978, one of the few times he publicly discussed his family. In the apartheid lexicon, “colored” meant mixed race.

“My mother, Welhemina Mbatha,” he added, “was a pitch-black woman who was proud of herself and was not prepared to take a nuisance from anybody.”

From his teenage years onward, Mr. Magubane lived under the tightening grip of apartheid — a ubiquitous web of racial legislation underpinning the strictly-enforced separation of South Africa’s white, Black, “colored” and Indian populations. The apartheid laws were so intrusive, he once said, that Black photographers were not allowed to share darkrooms with white colleagues.

His interest in photography began when his father presented him with a Kodak Box Brownie, although, by his own account, he completed his first professional assignment — photographing a conference of the African National Congress in 1955 — with a Japanese-made Yashica camera, also paid for by his father.

His career cost him his first marriage, to Gladys Nala. Ms. Nala, he wrote, objected to his erratic working hours and the late nights in which he slept at the office because there was no means of returning home. “So I had to choose between my career and my wife,” he wrote.

A second marriage, in 1962, ended in divorce three years later. A third wife died of cancer in 2002. His survivors include a daughter, Fikile Magubane, and a granddaughter.

As protests spread, Mr. Magubane’s work was punctuated by beatings and spells in prison. On occasion, the security police made him stand on three bricks for five straight days and nights. He moved from Drum to The Rand Daily Mail, a liberal newspaper, and covered the growing number of forced removals, when Black communities were trucked away to so-called “homelands” under the apartheid vision of separation.

After being kept in solitary for 586 days, he was released in 1970 only to be declared a banned person. The terms of his restriction meant that for five years he was not permitted to socialize with more than one other person at a time, and was not allowed to enter any school or newspaper office.

In his 1978 essay, Mr. Magubane gave a harrowing account of the impact of living “five years as a ghost.”

“There was no one to talk to,” he said, “even my sweethearts ran away like rats.”

He added: “My job as a newspaper photographer was finished. It meant the end of my profession.”

Even during the ban he was sent back to prison, in 1971, and served 98 more days in solitary confinement followed by six months in jail.

Throughout it all, he said, when he was held under repressive laws ostensibly intended to counter communism and terrorism, “I had never been convicted of any crime.”

As the Soweto uprising unfolded, he and other Black journalists were detained, this time for 123 days, and his house was burned down. But his images of the uprising brought international recognition, including a job with Time magazine in South Africa in 1978. He went on to record the unrest, protests and states of emergency of the mid-1980s that led to Mr. Mandela’s release.

Over time he published 17 books, exhibited widely and received seven honorary degrees and many awards, including the prestigious Cornell Capa Infinity Award in 2010.

In his later years, though, as he battled prostate cancer, he focused more on sunsets than protest, telling The New York Times in 2012: “I’m tired of dealing with dead people. I now deal with sunsets. They’re so beautiful. You see so many; it’s like meeting beautiful women.”