Violence against foreigners has flared up again in parts of South Africa.

Earlier this month, immigrants' homes and businesses were looted and torched in suburbs of Johannesburg and Pretoria, the capital city, raising concerns about anti-foreigner sentiment in the country.

The latest attacks follow previous bouts of xenophobic violence in 2008 and 2015 which resulted in the deaths of foreign nationals and the displacement of hundreds of migrants who were too afraid to continue living in the new communities they now called home.

With the end of apartheid and the dawn of democracy in 1994, South Africa opened itself up to the world.

A steady stream of migrants from around Africa made their way south in search of safety and better opportunities, in what was once the continent's fastest-growing and largest economy.

But nowadays, with the economy static and youth unemployment rising, some locals are accusing foreigners of stealing jobs and of being involved in criminal activities, such as drug peddling and prostitution.

Anti-immigrant sentiment is on the rise with community leaders and some in government echoing the dangerous rhetoric heard in parts of Europe and the United States.

On Friday, authorities gave permission to a group of people to hold an anti-immigrant rally in Pretoria. The march descended into violence when some protesters attempted to storm into a suburb of Pretoria West, which is home to a predominantly migrant community.

The migrants in the area mobilised and vowed to fight back as a large contingent of riot police had to be deployed to avoid large-scale violence between the two groups.