It’s a more complex story. Let’s look at SA first - during WW2 it experienced massive industrialization as the Brits relocated built key war effort industries down there due to SAs comparative advantages, namely abundance of natural resources, proximity to major shipping lines (Suez channel was closed off), no threat from Axis powers and most importantly a massive pool of dirt cheap unskilled and semi-skilled African labor.
In the immediate postwar period the economic boom continued and the Afrikaner white minority seized power, set on creating a whites-only ethno state under the maxi of total segregation. Like all utopian blood and soil ideas, they new National Party government encountered it’s biggest problem - who was supposed to do the shitty jobs if all inhabitants were recruited from the ranks of the supposed master race? They realized that the whites will suffer a massive drop in living standards and industrialists also freaked out realizing their bonanza years will come to an end.
So they devised a compromise solution, separation (apartheid) instead of segregation, meaning that they would get to reap all benefits of cheap African labor while keeping the out of sight whenever possible in satellite townships, subject to draconian laws controlling every minutiae of their existence.
Rich whites loved it because it enabled them an unparalleled lifestyle with a small army of domestic help, gardeners and cheap labor in general for the industry due to artificially suppressed wages for the blacks. You were a skilled black laborer who wanted to accept a better paying job? Not possible as your employer could legally prevent you from resigning due to a massive apartheid regulation apparatus who over organized everything.
White unions also loved it because cheap black labor subsidized artificially high wages for uneducated whites in fake jobs who would have otherwise been proper white trash.
So it worked, for a while - a small percent of the population lived a first world lifestyle with suburban swimming pools, cricket, weekend barbecues and absolutely didn’t give a fuck what the remainder of the population did in their shanty towns, usually only visible (and smelt) in the distance when driving on the highways surrounding major urban centers.
Brazil was a pretty similar story, although draconian separation was never enforced. In the last two decades of the 19th century Japanese de facto took over from black slaves the role of dirt cheap indentured labor on plantations. You don’t want to work or demand higher wages? Well I don’t give a fuck, I’ll bring boatloads of Japanese to replace you, only to rant about the Yellow Peril a couple of years later.
In the long term, this extreme inequality was not sustainable. You simply have to give something to the proverbial great unwashed - now, cynics will say that reality TV, legalized weed, affordable PS4/XBOX games and ubiquitous fast food restaurants are a form of wealth transfer used to placate the poorest classes so they don’t grab their pitchforks.