ALEXANDRA, South Africa — During apartheid, the government wielded the police like a club, using them to keep black South Africans in check and brutally extinguish any dissent.

In impoverished black townships like Alexandra, the enmity between the police and black South Africans was so bad in the mid-1980s that residents chased away black police officers who lived in the township by burning down their family homes.

But with the end of apartheid in 1994, change came quickly. The local police force here got its first black commander. Now, all but a handful of the Alexandra police station’s officers are black, and many live in the community. Police stations are no longer redoubts with gates and guards who restrict entry.

“Now when people want to come in, they just come in anytime,” said Col. Nhluvuko Zondi, who became a police officer in 1987 and the station’s first black female commander last year.