In 2007, Thalitha Mukansi moved to Diepsloot, an informal township on the northern fringes of Johannesburg. She was a social worker who settled in the region because it was what she could afford, and she liked working with, and helping, victims of assault.

But outside Ms. Mukansi’s window, assaults and rapes were common — sometimes even daily, she said. She tried to tune out the constant violence, but she didn’t know how she could possibly do that.

“The things I was seeing in front of me — it feels like being helpless,” she said.

Diepsloot, established in 1995, is home to approximately 138,000 predominantly poor African migrants. The transient environment, poor economy and lack of jobs have made it one of the most violent settlements in South Africa’s Gauteng province. Close to 2,300 violent crimes, such as murder or violent assaults, were reported to the police between 2017 and 2018. Sex crimes are particularly common. In 2016, more than half the men surveyed in the township admitted to raping or assaulting women. Last year, Diepsloot ranked 17th in South Africa for reported attempted sexual offenses and 28th for rape, according to crime statistics from the South African Police Service.