Police have arrested a Pakistani man accused of opening fire on a crowd of protesters and injuring several people in a South African town east of Pretoria.

Township residents hurled rocks and barricaded roads on Tuesday while protesting against the murder of a boy, allegedly beaten to death with a golf club by a Pakistani shop owner.

"The boy was assaulted by one of the Pakistanis allegedly because he was stealing sweets," said the police. "He died in hospital yesterday."

His death led to residents rampaging overnight on Tuesday, ransacking around 15 foreign-owned shops, according to police.

"One Pakistani guy was trying to get out of the protest area, and he was firing shots towards the protesters," police spokeswoman Marissa van der Merwe said, according to AFP news agency. The suspect was arrested.

Police said both South Africans and Pakistanis had been wounded in the clashes, but did not give specific numbers.

The South African Press Association reported that occupants of a vehicle trying to leave the area shot at protesters on Wednesday, according to AP news agency.

With poverty rife and unemployment widespread, frustration in South Africa's run-down neighbourhoods often boils over into anti-immigrant violence. Deadly attacks in 2008 killed more than 60 people and displaced thousands into refugee-style camps.

Cullinan is east of Pretoria, the capital, and has yielded some of the world's most famous diamonds.

Source: Agencies