Chanting and singing, machete-armed residents burned down shops owned by foreigners, including a Nigerian dealership in the nation's largest city.
Immigrants carrying bricks accused police of not doing enough to protect them as businesses smoldered.
Five people killed
Violence targeting immigrant shops started recently in the port city of Durban, where two foreigners and three South Africans were killed. Residents have accused African immigrants of taking their jobs and committing crimes. The unemployment rate in South Africa is 25%, according to government figures.
President Jacob Zuma slammed the assertion, saying his government is addressing social and economic issues brought up by citizens. He said immigrants contribute to the nation's economy while others bring scarce skills.
"While some foreign nationals have been arrested for various crimes, it is misleading and wrong to label or regard all foreign nationals as being involved in crime in the country," Zuma said.
As the violence spread to other cities, terrified immigrants sought a resolution. Others fled, taking refuge at police stations in major cities.
"They are using this as scapegoats," said Jean-Pierre Lukamba, an immigrant from the Democratic Republic of the Congo.
"Every day, migrants are living in this fire. It's not just attacks. It's institutionalized xenophobia. The government must do something. Those people aren't just mad for no reason. They want electricity, they want jobs, they want water."
'They don't understand the history of Africa'
Lukamba said he's part of an organization trying to negotiate between the two sides.
"They don't understand the history of Africa; if they do, they would know each of us, we are one," he said.
Thousands fled to temporary shelters, with aid group Gift of the Givers saying about 8,500 people are hiding in refugee centers or police stations this week because of the violence. The number did not include those who have moved in with friends or relatives.
The aid group said it has a facility in Johannesburg to help those who might need shelter.
"There has been an outpouring of support from ordinary South Africans who are disgusted with the attacks not only because they are foreign, or African, but because they are fellow human beings," Gift of the Givers said.
"We are preparing aid packages for those who may journey onwards to their home countries."
Police ordered to work around the clock
Though Zuma has condemned the attacks and appealed for calm, the violence spread from Durban to Johannesburg.
"No amount of frustration or anger can ever justify the attacks on foreign nationals and the looting of their shops," he said. "The attacks violate all the values that South Africa embodies, especially the respect for human life."
Zuma said he has ordered police to work around the clock to protect citizens and immigrants, and arrest the perpetrators.
In the past, Johannesburg has been the epicenter of anti-immigrant tensions.
In 2008, dozens were killed in attacks in the poorest areas of Johannesburg. Most of the victims were Zimbabweans who had fled repression and dire economic circumstances. In those attacks, police arrested more than 200 people on various charges, including rape, murder, robbery and theft.