Nigerian police officers beef up security during a protest in Abuja, capital of Nigeria, Sept. 4, 2019. South Africa has closed its embassy in Lagos after a spate of attacks on South African businesses in response to anti-foreigner violence in SA. File photo: Xinhua/Olatunji Obasa.

Cape Town - South Africa closed its embassy in Nigeria's commercial capital Lagos after a spate of attacks on South African businesses in response to anti-foreigner violence in South Africa, the government said Thursday.

The embassy temporarily closed out of concern for the safety of its staff, said foreign affairs spokesman Lunga Ngqengelele.

"We have been in communication with the Nigerian government and we have been assured of the protection of the businesses belonging to South Africa," Ngqengelele told local broadcaster eNCA.

The vandals attacked numerous South African-owned businesses in Nigeria, including South African telecom giant MTN, supermarket chain Shoprite and clothing retailer PEP.

The violence broke out in reprisal for a wave of attacks at the weekend against foreign African nationals in South Africa's Gauteng province.

Botswana meanwhile issued a travel advisory warning its citizens to "exercise extreme caution" and remain vigilant at all times in South Africa.

Five people were killed and more than 300 people have been arrested since the violence erupted, in which shops were looted and vehicles torched. Most affected were South Africa's economic hub Johannesburg and capital Pretoria.

The African Union, Nigerian President Muhammadu Buhari and South African President Cyril Ramaphosa have all condemned the xenophobic violence.  

In Nigeria, the reprisal attacks took place in Lagos, as well as the capital Abuja, the university town of Ibadan and the city of Uyo, Nigeria's government said in a statement.

Numerous South African-owned businesses have closed and been placed under police protection. 

Thousands of students Wednesday protested in Zambia's capital Lusaka. The students also attempted to attack and loot several South African businesses.