Gang violence and organised crime remain rife in South Africa, despite government efforts to curb one of the highest per capita murder rates in the world, including by deploying the army in some areas.
In Wedela township, about 80km from Johannesburg, 17 people were killed and 15 injured at a tavern, the South African Police Service said in a statement posted on X on Sunday.
"Suspects were reportedly armed with AK-47 rifles and pistols," the statement said of the shooting, which occurred about 9.30pm (1930 GMT) on Saturday.
The motive was unclear and no arrests had been made, the statement said.
In a separate attack in the township of Lwandle on the outskirts of Cape Town, gunmen opened fire in a venue selling grilled meat about 1.46am on Sunday, police said.
Five people died at the scene, another five died of injuries after being transported to medical facilities and 11 others were receiving medical treatment, police said.
"Detectives are hard at work in search of the perpetrators of the shooting incident with no arrests effected yet," the statement said.
Crime is expected to be a major issue for voters in municipal elections in November, when the African National Congress faces further erosion of voter support.
A shooting at a house party near Durban last week killed 11 people, while a series of women's bodies found near Johannesburg since July has renewed fear and anger over high rates of femicide.