JOHANNESBURG (AP) — Only a few kilometers (miles) separate Alexandra, a gritty Johannesburg township where South Africans attacked immigrants last week, from Sandton, a district jammed with high-end stores, restaurants and gleaming office towers symbolizing the upper reaches of the prosperity that attracted so many job-seekers to South Africa.

Adding to South Africa’s allure was its image as a “rainbow nation” of diversity and inclusion after white racist rule ended in 1994. Now a nation that seeks to lead in Africa is struggling with perceptions that some of its communities breed intolerance toward foreigners, many from elsewhere in Africa.

The violence against immigrants and the looting of their shops that erupted this month in parts of Johannesburg and the coastal city of Durban appear to have abated after the deaths of three South Africans and four foreigners. On Tuesday, April 21, Alexandra was bustling as uniformed students walked home after school and a few police cars patrolled streets lined with shacks made of sheet metal.

The unrest, however, has been a public relations disaster for South Africa, a country that a visiting Zambian said had been perceived as a “heaven of Africa” because of its relative wealth, stability and freedom.

The Zambian, Dennis Nyati, was attending a Johannesburg conference hosted this week by African Monitor, a South Africa-based group that promotes development. Another delegate, Yoadan Workneh Shiferaw of Ethiopia, speculated that South Africans involved in the attacks had forgotten “how cruel it was during apartheid,” when the country’s white minority rulers harshly suppressed dissent.

She said: “Now they’re doing it to someone else.”

More than 2,000 Mozambicans have returned home from South Africa because of the violence, Mouzinho Saide, Mozambique’s deputy health minister, said Wednesday. Hundreds of immigrants have also taken buses back to Malawi and Zimbabwe. As many as 7,000 immigrants are living in South African refugee camps after fleeing their homes, according to Doctors Without Borders.

More than 300 suspects in the unrest have been arrested around the country, the government said, including several people accused of attacking a Mozambican man in Alexandra while a local photojournalist took pictures of the fatal assault.

Namibia’s chamber of commerce and industry canceled a trip to South Africa that was scheduled for May because of the anti-immigrant attacks, the Namibia Press Agency reported. No official business delegation from Namibia will visit until “we are assured that the South African government is in full control of its unruly citizens,” the agency quoted chamber head Tarah Shaanika as saying.

Many South Africans have organized marches, concerts and social media campaigns to condemn the violence. It is a bitter time for a country that was the focus of international attention in December 2013 when foreign leaders traveled to Johannesburg to pay tribute to Nelson Mandela, the anti-apartheid leader who became South Africa’s first black president, after he died at the age of 95.

“Our rainbow nation that so filled the world with hope is being reduced to a grubby shadow of itself more likely to make the news for gross displays of callousness than for the glory that defined our transition to democracy under Nelson Mandela,” said a statement from a foundation named after retired Archbishop Desmond Tutu and his wife Leah. Tutu and Mandela were both awarded the Nobel Peace Prize for their efforts to end apartheid.

South Africa’s national parks service, a key driver in the tourism industry, said some bookings from neighboring countries had been canceled because of the anti-immigrant attacks.

“A large proportion of guests to our national parks are international visitors and we appear to be sending a message that foreigners are not welcome in our country,” the parks agency said in a statement.

Tensions with immigrants, accused by some South Africans in poor areas of seizing economic opportunities at their expense, set off attacks that killed about 60 people in 2008. Several people died in similar attacks in Johannesburg’s Soweto area in January.

High unemployment, a deep gulf between rich and poor and one of the highest rates of violent crime in the world cause social tensions in South Africa, even though it has one of the biggest economies on the continent. The recent attacks mostly targeted low-income areas where immigrants are embedded in the communities, and wealthy areas such as Sandton were untouched.

Some South Africans wondered what happened to the early promise of post-apartheid South Africa, recalling a comment by Mandela during his inauguration in 1994.

Mandela said at the time: “Never, never and never again shall it be that this beautiful land will again experience the oppression of one by another and suffer the indignity of being the skunk of the world.”