Several South African cities are grappling with violent attacks against foreigners. These are the worst xenophobic attacks in a decade in South Africa, with five people killed and thousands displaced in the last few weeks. What are the reasons behind this violence?

In the usually quiet coastal city of Durban, in Kwazulu Natal Province, South Africa, the latest wave of xenophobic attacks started a couple of weeks ago in townships. Shops owned by foreigners were looted. Tension kept on scaling up and soon reached the city center as foreigners continue to flock to refugee camps.

But how did it all start? For Kwazulu-Natal violence monitor Mary De Haas, all it needed was a spark. In this case, it came from King Goodwill Zwelithini of the Zulu tribe, which is in the majority in the province, when he said that all foreigners should go home. Attacks started soon after.

"I think it's been brewing for quite a while. I'm told that even before the king made this famous speech about foreigners must go, that there was a lot of lobbying to get rid of foreign business people because they were competing with the locals,” she explained. “People use what the king said as a pretext, as "well the king has given us the go ahead so let's do it".

It is not the first xenophobic attack that South Africa has faced. In 2008, 62 people died in similar anti-immigrant attacks. The main grievance is that foreigners are taking South African jobs.

Last year, the national unemployment rate reached 25 percent, its highest level since 2008. More than half the South African population lives under the poverty line.

Locals claim foreign shop owners slash their prices because they dodge taxes. They say foreign workers work for low wages and break the market for the locals. De Haas said all the assertions, even if not all are true, lay bare the dysfunction of the state institutions.

"There is all sort of resentment, ranging from fairly unsophisticated local people who are crossed because the local business seem to be doing well. To the more sophisticated people... about the failure of the immigration authority to stem the influx of residents," she said.

"Also allegations that some of these people are voting here illegally because home affairs has provided with documentation. And the home affairs is very corrupted, which again gets back to resentment over resources, economic, political resources, which of course lies at the heart of this, no doubt," said De Haas.

De Haas said that these attacks did not happened out of the blue. "I don't think it's spontaneous. I think it's pretty well-planned. It should've been picked up and detected. People have been talking about this,” she stated. “I mean one man said to me, 'no, the feeling is foreigners must go, if they don't go, by December, there must be a bloodbath.' Now people have been talking about this for months, why has the police not be proactive?"

As Durban still experiences violence, similar xenophobic attacks have spread to other cities the last few weeks, including Pietermaritzburg and Johannesburg.