Twelve people were killed earlier this month when mobs attacked foreign-owned businesses, mainly in Johannesburg.
A special envoy from South Africa presented an apology to Nigeria's President Muhammadu Buhari on Monday.
The envoy, Jeff Radebe, expressed the country's "sincerest apologies" at a meeting in the Nigerian capital, Abuja.
"The incident does not represent what we stand for," he said, adding that South African police would "leave no stone unturned" in bringing those involved to justice.
Mr Radebe also told President Buhari that the South African government condemned the violence and was taking decisive action.
Mr Buhari thanked Mr Radebe for "coming to explain to us what happened in South Africa recently, leading to [the] killing and displacement of foreigners".
"President Buhari responded to profuse apologies from the South African president, pledging that the relationship between the two countries will be solidified," a statement from his office said.
At the end of last week, South Africa's President Cyril Ramaphosa told the BBC that he felt ashamed by the recent violence.
"We are very concerned and of course as a nation we [are] ashamed because this goes against the ethos of what South Africa stands for," he said.
South Africa's President Cyril Ramaphosa has said he feels ashamed by the violence
No Nigerians were killed in the violence in South Africa, but Nigerian-owned shops and businesses are believed to have been targeted by the mobs.
Of the 12 people who were killed, 10 are reported to have been South African nationals and two were from Zimbabwe.
Nigeria has been outspoken in its condemnation of the violence. A fortnight ago, it withdrew a delegation from a major international conference taking place in South Africa.
Tensions were inflamed after videos and images were shared on social media purporting to show Nigerians being attacked and killed. The Nigerian government said there was no evidence that this had taken place.
But it did say that Nigerian-owned businesses had been targeted.
South Africa has become a magnet for migrants from other parts of Africa as it has one of the continent's biggest and most developed economies.
Evacuation of Nigerians
But there is also high unemployment in the country and some people feel foreigners are taking their jobs.
While the diplomatic mission is taking place, Nigeria has continued to evacuate its citizens from the country.
Last week, Nigeria's Consul General Godwin Adama said only those who were under distress as a result of the attacks would leave South Africa.
More than 300 Nigerians are expected to arrive in Lagos on Tuesday. Last week, 188 evacuees arrived back.