But that was hardly the last word. The Twitter battle, which broke out a few months ago and featured dueling hashtags (#capetownisracist and a countercampaign, #capetownisawesome), has given way to soul-searching in this city of 3.5 million people at the southern tip of Africa: Does this nation’s celebrated rainbow end where the mountain meets the sea?

This is the only major metropolis in South Africa where black people are not the majority, and it remains deeply divided. The particularly harsh legacy of apartheid as it was carried out here has left especially deep scars that still demarcate the geography: whites in the city center and its mountainside inner suburbs, nonwhites in the distant townships on the Cape Flats. Apartheid policies effectively barred blacks from living or even working in the city, giving so-called colored, or mixed-race, people, today the city’s largest ethnic group, priority over blacks for jobs and housing.

Beyond history, there is present-day politics. Western Cape is the only one of the country’s nine provinces not run by the governing African National Congress. It is run by Ms. Zille’s Democratic Alliance, which grew out of the white anti-apartheid movement but ultimately came to include remnants of the old National Party that created apartheid.

Image Apartheid left deep scars that still demarcate Cape Town. Credit... The New York Times

In a speech last year in a black township near Cape Town, South Africa’s president, Jacob Zuma, said the city had an “extremely apartheid system,” according to local newspaper reports on his remarks. The African National Congress is trying to win the province, and the Democratic Alliance has dismissed the assertion that Cape Town is racist as a political ploy.