South African police said on Wednesday that two people suspected of looting shops in South Africa’s capital were shot dead in continued violence triggered by the ruling party’s choice of a mayoral candidate for local polls.

Police said they had also arrested 40 of the rioters who were targeting foreigners’ shops as public anger mounted over economic hardships in the build-up to elections on 3 August that are likely to become a referendum on president Jacob Zuma’s leadership.

Residents of Pretoria’s townships started setting cars and buses alight on Monday night after the ruling African National Congress (ANC) named a candidate in the Tshwane municipality where the capital city is located, overruling the choice of regional branches. Burned-out cars blocked roads on Wednesday.

The two killed were shot on Tuesday night, the police spokeswoman for Gauteng Province, Colonel Noxolo Kweza, said.

“Two of the suspects were shot and killed following looting at Mamelodi,” police said in a statement, adding that those arrested would face charges of violence and theft.

“Incidents of protests and looting continued in other areas while situation is tense in others.”

Violence continued in parts of the capital on Wednesday.

Protesters continued to clash with police and “a disproportionate part of the looting was taking place at shops owned by foreign nationals,” Tshwane Metro police spokesman Console Tleane told eNCA television.

“There is calm in some hotspots [but] the navigation of the streets is difficult because of the rubble and the debris,” he said.

Foreigners, many of them from other African countries, were attacked in April last year by crowds blaming them for taking jobs and business.

Analysts warned of more unrest in the commercial hub of Gauteng province, which includes Pretoria and Johannesburg.

“Intra-ANC, election-related, factional violence is being ignored by markets trading on external factors, but is worrying,” Peter Attard Montalto, a London-based Nomura emerging markets analyst, said.

The mayoral dispute flared at the weekend after an ANC member was shot dead on Sunday as party factions met to decide on a candidate for mayor of Pretoria’s Tshwane municipality.

The ANC leadership then named senior party member and former cabinet minister Thoko Didiza as its candidate for Tshwane, overriding regional branch members and refusing to back down as the violence mounted.

The ANC said it picked the candidate as a compromise between two rival factions in Tshwane. But critics say the decision by the party, which has been in power since the end of white-minority rule in 1994, showed that it is losing its touch in areas where it was once unassailable.

Zuma survived impeachment in April after the constitutional court ruled he had breached the constitution by ignoring an order by the anti-graft watchdog to repay some of the $16m (£11m) in state funds spent renovating his home.

“Ahead of the August elections, disgruntled ANC supporters in Gauteng will be motivated by the Pretoria riots to stage further protests to demonstrate the unpopular ANC leadership’s decisions,” Robert Besseling, the head of the EXX Africa business risk intelligence group, said.

• This article was amended 23 June 2016. An earlier version said incorrectly that South African police said they had shot the two looters.