The attacks have included rape, people being burnt to death and beatings.
Businesses have been looted and homes set ablaze. Attacks continue to be reported.
Up to 100,000 people are estimated to have been left homeless due to the violence.
More than 2,000 foreigners are living in a makeshift refugee camp in the Cape of Good Hope, a tourist spot on South Africa's Atlantic coast.
Al Jazeera's correspondent Kalay Maistry, reporting from transit camps set up in Maputo, Mozambique's capital, said that the migrants had left behind relatives, friends, properties and jobs.
"There are thousands of people crossing the border coming back home.
"They are doing so out of sheer desperation.
"Many of them had opted to stay in South Africa, but since the violence, they have had little choice but to return to their homeland to try to salvage some sort of lifestyle many of them have lost."
The Mozambique government has assisted those returning to the country by providing documents for those who have lost them, food, transport and medical assistance.
"Nobody stays [in Maputo] for longer than 48 hours. They stay until a bus is available to take them away from the capital. Many of them live in rural areas.
"The government has given them a small pack with groceries so that they can at least get home and not be starving."
Maistry reported that a problem re-absorbing the migrants back into Mozambique's economy is emerging.
"The majority of them said that they will wait for it to get quiet in South Africa. As far as they are concerned their future still lies in that country."
Pat Craven, a spokesman for the Congress of South African Trade Unions (Cosatu), told Al Jazeera that poverty, unemployment, a lack of housing and the slow delivery of services were the root cause of the violence.
"We have been warning for years [that it] is a time bomb ticking away.
"It is clearly an indication of utter despair on a very small section of unemployed poverty-stricken South Africans, who have decided to make scapegoats of migrant workers from other countries."
People have fled violence in Johannesburg and Cape Town.
Thabo Mbeki, the South African president, has described the attacks as an "absolute disgrace."