An anti-foreigner mob of about 1,000 people rampaged across South Africa's capital city on Friday, assaulting and looting, in the latest dangerous escalation of tensions over immigration here.

The march nearly turned disastrous when the mob entered a Pretoria neighbourhood dominated by Somali migrants. Hundreds of foreigners confronted the mob, the two sides separated by only a few metres, with both sides wielding bricks, wooden poles and other weapons. Police finally managed to disperse them with stun grenades, rubber bullets and water cannons.

Many South Africans accuse the foreign migrants of causing unemployment and crime, despite evidence that the migrants create jobs by opening businesses and employing locals.

Story continues below advertisement

Anti-foreigner attacks have remained frequent in South Africa this year, at a time of economic stagnation, high unemployment and rising crime.

The attacks on foreign migrants – largely Nigerians, Zimbabweans and Congolese – have caused a growing rift between South Africa and other African countries. The Nigerian government has protested the attacks this week, calling on the African Union to "intervene urgently" to prevent more bloodshed.

The violence has sparked retaliatory attacks in the Nigerian capital, Abuja, where one group of protesters on Thursday ransacked a shop owned by MTN, a South African cellphone company. After protesting the anti-foreigner violence in South Africa, they broke into the shop and stole cellphones and laptops. Police were deployed to guard the store.

South Africa has suffered anti-foreigner violence in the past, mostly notably in 2008 and 2015 when dozens of foreigners were killed by mobs. Attacks have erupted again in Johannesburg and Pretoria over the past week, on the pretext of targeting drug dealers and brothels. Dozens of foreigners saw their homes ransacked, robbed or destroyed in arson attacks. In one case, a beer-drinking mob invaded a Nigerian church, assaulting the Nigerian pastor and his congregants and leaving them with bloody injuries.

At the same time, another group announced the formation of an anti-foreigner political party, South African First, which vowed to force all foreigners to leave South Africa within 48 hours of winning power. It claimed falsely that 13 million foreigners lived in South Africa. In reality, government surveys have found that only 1.6 million foreigners live in the country, less than 3 per cent of its population.

The violence in Pretoria on Friday began when an anti-foreigner group – supported by the new political party – obtained permission to march to government offices.

The group carried an official memorandum blaming foreigners for a long list of problems: everything from illegal taxis and untidy churches to unfair hair-salon competition. It even demanded a government program to teach foreigners to speak more politely. "They are arrogant and they don't know how to talk to people," the memorandum concluded.

Story continues below advertisement

At least one person in the anti-foreigner march carried a placard supporting U.S. President Donald Trump. "Donald come and save us," the sign read.

When they reached the Somali neighbourhood, many of the marchers wore masks and carried sticks and stones. They nearly came to blows with the foreign migrants, until police deployed armoured vehicles, a helicopter, tear gas and rubber bullets to disperse them.

Even before the march, groups were attacking foreign-owned shops around Pretoria. During the day, the rampaging mob marched for about 15 kilometres through the city, assaulting Zimbabwean and Malawian pilgrims at a church service and destroying their mobile kitchens.

"Foreigners must go," the mob sang after one assault. "We will kill them. They are destroying South Africa."

By early afternoon, police said they had arrested 136 people over the previous 24 hours. But the violence continued later in the afternoon on Friday, with more confrontations in Pretoria's city centre.

South African President Jacob Zuma appealed for calm. But he also seemed to be supporting the marchers, saying that the organizers were merely protesting against crime. "It was not an anti-foreigners march," he said on Friday, disregarding all of the evidence.

Story continues below advertisement

Mr. Zuma complained that the march had been "hijacked" by people with "ulterior motives." The organizers of the march had valid concerns about crime, he said.

In an attempt to defuse the tensions, the government announced on Thursday that it had arrested 63 foreign workers at a supermarket chain who lacked official documentation.

Amnesty International said the South African government has fuelled the anti-foreigner attacks since 2008 by failing to arrest the perpetrators and tolerating a "toxic populist rhetoric that blames and scapegoats refugees and migrants."

It warned that the situation in Pretoria is "precariously balanced" and could easily escalate into serious violence.

The Nelson Mandela Foundation, a charity created by the late president and anti-apartheid hero, said it was shocked that the authorities had given permission for a "march of hatred" in Pretoria on Friday.

The foundation condemned the attacks on foreigners. Failure to halt the attacks will "set us back decades as a stable democracy," it said.

Story continues below advertisement

The Nigerian embassy in South Africa set up a hotline where Nigerians could report attacks on foreigners. The Nigerian government advised its citizens in South Africa to be vigilant, and it urged South Africa "to bring perpetrators of these deplorable acts of violence to justice."