Most of the recent unrest occurred in and around the coastal city of Durban, where police said two foreigners and three South Africans were killed.
The dead included a 14-year-old boy who was allegedly shot during looting last night and died at a hospital, police Col Jay Naicker said. Some 34 people have been arrested for possession of unlicensed firearms and other crimes in the last two days, he said.
Despite the increased police presence, authorities are hard-pressed to stop unrest that recalls similar violence in South Africa in 2008 in which about 60 people died.
In January this year, four people died during a week of looting of foreign-owned shops and other violence in Soweto and other areas of Johannesburg.
Some South Africans have accused immigrants of taking jobs and opportunities away from them. The latest violence followed reported comments by Zulu King Goodwill Zwelithini, an influential figure among the Zulu ethnic group, that foreigners should "pack their bags" and leave.
The southern African nation of Malawi plans to repatriate at least 400 of its citizens following the attacks in South Africa, said Kondwani Nankhumwa, Malawi's information minister.
Malawi is currently in discussions with South Africa to arrange temporary travel papers for stranded Malawians because most lost their passports in the chaos, Nankhumwa said.
"Most of them fled with literally nothing to safe camps," the minister said. "The numbers will swell since some Malawians are in hiding."
South Africa President Jacob Zuma condemned the violence and assigned several Cabinet ministers to work on the problem with officials in KwaZulu-Natal province, which includes Durban.
It quoted the president as saying that many foreign nationals are living legally in South Africa and are contributing to economic development.
