JOHANNESBURG -- In South Africa, all that glitters is gold.

Stock markets may crash in New York, London and Tokyo, the world's industrial powers may impose punitive trade sanctions on South Africa, and foreign corporations may pull their capital out.

But at the end of the day, the economic reality in South Africa is gold, and everything else is little more than a sideshow. And never has that reality been demonstrated more clearly than during the current worldwide equity-market crisis.

"Investors in South Africa are far more concerned with advances in the gold price -- the key to the entire domestic economy -- than with swings in share prices overseas," said one Johannesburg stockbroker following a boom in the local stock market two weeks ago.

Since Wall Street's Black Monday, there have been up-and-down flutters in the price of gold resulting from investor uncertainty, attempts by futures speculators to force an upward price momentum, and from moves by central banks around the world to stabilize the dollar.

Similarly, there have been spasms in the Johannesburg Stock Exchange since the world stock market collapse. The market climbed initially to a record high on the expectation that world investors would take cover in gold and then plunged 12 percent the next day when Wall Street's resurgence seemed to dash these hopes.

Brokers here noted with relish that South African mining houses remained insulated from the local turbulence because investors, including those abroad, rushed for shares in the big gold mining companies.

Despite the swings and spasms -- much less severe than elsewhere in the world -- gold remained not far off the $480-per-ounce price to which it had climbed last week, and local brokers remained guardedly optimistic that weakened confidence in other investment assets would fuel world demand for gold and drive up its price even more.

Since gold was first discovered outside Johannesburg in 1884, it has dominated South Africa's economic life, lifting it above the destitution of its African neighbors while at the same time profoundly affecting its racial policies and its attitudes toward international pressure for racial reform.

South Africa produces more than half of all the gold mined annually in the noncommunist world, and its underground reserves are estimated to account for about half of all the recoverable gold that exists in the world, assuring it of a long future of prosperity.

Gold accounts for nearly half of South Africa's export earnings -- bringing in $8 billion last year, bolstering the Treasury with a $3.5 billion trade surplus, and rendering South Africa essentially immune to trade sanctions imposed by the United States and other countries. Mining exports, including gold, diamonds, coal and strategic minerals, account for 60 percent of the country's export earnings.

The general rule of thumb in the industry is that every $50 increase in the price of an ounce of gold means a $1 billion increase in South African export earnings. A $50 price increase looks plausible when viewed against the longstanding $35-per-ounce price of gold in 1974 and the jump from $280 an ounce in 1985 to more than $450 just two years later.

Industry executives and western diplomatic analysts interviewed estimated that even though gold exports this year will drop in volume to 600 tons from last year's 640 tons, gold revenue will increase because of the rising price on the world markets.

A study by Stellenbosch University economists estimates that South Africa's total export revenue this year will show a barely perceptible decline despite a full year's imposition of punitive trade sanctions, a weakening of the international economy as a whole and a rebound of the South African rand from its downspin during last year's racial upheavals, which reduced the competitiveness of South African products.

The Central Bank forecast a 3 percent growth rate for South Africa this year, and current projections suggest a slightly more modest performance because of reduced private fixed investment, reduced exports apart from gold, and weakness of the world economy generally. However, the Standard Bank of South Africa is now forecasting a 5 percent growth in the gross domestic product next year.

Nowhere is the cushioning power of South African gold displayed so starkly as in the effects of the antiapartheid sanctions legislation adopted by the U.S. Congress in October 1986 over President Reagan's veto.

At the time, Sen. Nancy Kassebaum (R-Kan.), chairman of the Senate subcommittee for African affairs, estimated that sanctions would cost South Africa $350 million in the first year. However, U.S. economists predicted that an $18-per-ounce rise in the gold price at then current sales levels would more than cover the export losses.

A year later, their estimates have proved to be not far off the mark.

According to some independent estimates, sanctions have affected 2 percent to 3 percent of South Africa's current total exports of roughly $15 billion, which squares with Kassebaum's prediction.

At the same time, the price of gold has increased several times over the required $18-an-ounce sanctions cushion, a testament to the ineffectiveness of the antiapartheid measure if the intent was to strike a warning blow to South Africa's economy.

It is little wonder then, economic analysts here say, that the government of President Pieter W. Botha feels sanguine about the effects of sanctions and disinvestment -- in the short run, at least -- and that South Africa's captains of industry have not yet become overwrought about the collapse of the world's equity markets.

"In reality, we have gold. Saudi Arabia has oil. New Zealand has sheep. We have gold. We exploit it efficiently and we do what any developed country would be expected to do, which is turn it to our advantage," said an executive of one of South Africa's largest gold-producing companies.

Revealing a sensitivity many liberal white businessmen have toward South Africa's built-in cushion against international pressure, the executive added, "There is so much in this country that is indefensible that is hard to be lumped in with the indefensible. But if we are, so be it." The executive spoke on the condition he not be identified by name or firm.

Another industry analyst noted that increases in the price of gold reinvigorate business confidence in South Africa, which sank to rock bottom at the outset of last year's sanctions and disinvestment campaigns.

At the same time, the analyst said, gold price increases tend to enhance a feeling of defiance and invincibility within the government and, as a result, tend to color political considerations of how to deal with international pressure for dismantling apartheid.

"It gives them a certain amount of leeway to tell the world where to get off," said the analyst.

At the same time, gold revenue is important for South Africa's purchase of imported goods -- a luxury for a country facing tight credit restrictions from international lenders.

"Growth in South Africa is highly geared to imports," said one industry analyst. "With the squeeze on foreign capital, we have to pay for all imports through current accounts, so every dollar that comes in from gold helps to pay for imports," he added.

Viewed from another perspective, gold also provides funds for the government's program of cautious, incremental political reform and, as government officials like to point out, reform costs money.

The government's three-phase strategy for stemming what it calls the "revolutionary onslaught" by leaders of South Africa's black majority consists of restoring order through security clampdowns, pacifying black townships through costly upgrading of housing and the service infrastructure and, finally, giving blacks an as-yet-undefined role in governing the country.

The second phase will cost millions, lending increased importance to export revenue, government officials point out.

Industry executives say that they are aware of some clouds around the gold lining.

For one, the demand by fabricators of gold products, mostly jewelry, appears to be flattening out at a time when the three major noncommunist gold-producing competitors -- the United States, Canada and Australia -- are increasing their combined production to nearly half that of South Africa's.

Simultaneously, the Communist Bloc countries last year doubled their 1985 sales to an estimated 402 tons, providing additional competition. China emerged as a major seller to the noncommunist world for the first time in a decade.

Extra gold supplies, say some analysts, could cause a yearly gold surplus of more than 20 million ounces, which could drive the price down.

Moreover, although the gold price has shot sky high in relation to the U.S. dollar, its level against other major currencies -- including those of such important South African trading partners as Japan and West Germany -- has not kept pace, gold executives say.

Additionally, if the stock markets continue to fall and a worldwide recession occurs, a prolonged interest in gold as a safe haven could not be counted on, according to market analysts. They noted that during most of the 1980-81 recession, which was caused by oil price rises, the price of gold fell.

One senior mining company executive here said there is a danger in becoming too complacent about the insular effects of gold.

"When the Dow Jones slipped 22 percent on Black Monday, we all smiled and said, 'Okay, we can go home,' " because we knew gold was going to go up. We thought everybody would say, 'Buy gold,' " the executive said.

But the gold price has held steady at about $470, he said, because "people are so shocked, so unsure of their judgment that they don't know what to do with that cash.

"But what if the herd syndrome takes over and everyone says, 'Sell gold?' " the executive asked.