Violence against immigrants in South Africa has killed at least five people since last week in one of the worst outbreak of violence against foreigners in years.

Hundreds of migrants mostly from other African countries had been forced out of their homes, authorities told the Associated Press news agency on Tuesday.

Khadija Patel, a South African journalist, told Al Jazeera there have been previous instances of violence against foreigners.

"Hundreds of foreign nationals were displaced in Isipingo [20km south of Durban] late last month, when a group of South Africans attacked foreigners living and working in the area. The victims of that continue to reside in a makeshift camp at a sports ground in Isipingo," Patel said.

"The Isipingo attacks was blamed on a labour dispute at a local wholesaler, and government refused to categorise the violence as xenophobic violence," Patel added.

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 on Monday night and died at a hospital, Jay Naicker, police spokesperson, said.

About 34 people have been arrested for possession of unlicensed firearms and other crimes in the last two days, he said.

"Police are deployed and in high alert in most of the areas where there are foreign nationals," Naicker said in a statement.

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, four people died during a week of looting of foreign-owned shops and other violence in Soweto and other areas of Johannesburg, stores owned by foreigners in Johannesburg are closing for fear of the violence spreading.

Zulu king's comments

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.

Zwelithini has since appealed for an end to the unrest, and says he has been misquoted, but many of those rioting were heard chanting "the King has spoken", Patel said.

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," Nankhumwa 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.

The government is addressing South African citizens' "complaints about illegal and undocumented migrants, the takeover of local shops and other businesses by foreign nationals as well as perceptions that foreign nationals perpetrate crime", Zuma's office said in a statement.

Zimbabwean presence

Zuma's statement quoted the president as saying that many foreign nationals are living legally in South Africa and are contributing to economic development.

On a visit to South Africa last week, Zimbabwean President Robert Mugabe thanked South Africa for hosting many Zimbabweans and said Zimbabwe would work with South Africa to improve border security.

It is estimated that as many as three million Zimbabweans are living in South Africa, many as illegal immigrants.

The violence against immigrants is "an expression of a terrible failure of memory by South Africans" who endured racial intolerance under apartheid, two South African foundations said.

The foundations are named after anti-apartheid leader Nelson Mandela, who died in 2013, and Ahmed Kathrada, another campaigner against the white racist rule that ended in 1994.

In a statement, the foundations welcomed efforts by Zuma and other senior leaders to stop the unrest, but said: "For too long, South Africans in leadership positions have either ignored the crisis or stoked the fires of hatred."