Athlone police responded to a suspected gang shooting in Kewtown, Cape Town, on Sunday evening at around 20:00 when they came under fire.
A shootout ensued between police and unidentified assailants, but no injuries were reported.
Western Cape police spokesperson Brigadier Novela Potelwa told News24 the man was taken into custody.
"Police are investigating a case of attempted murder and discharging of a firearm," she said.
She said police have "intensified crime prevention patrols" in the area.