As an investment, gold’s shining moments come and go. It is having one now, and not without reason.

There are few subjects in the investing world more contentious than the shiny, yellow metal. Some argue it is an essential holding to guard against inflation. Others see it as little more than a barbarous relic with subpar returns. Warren Buffett famously argued for stakes in productive, growing companies over a giant, inert cube containing all the gold in the world, quipping, “You can fondle the cube, but it will not respond.”

This debate has been rekindled with gold hitting record highs above $2,100 an ounce this month. An examination of gold’s long-term record doesn’t fully vindicate either side. It has badly trailed stocks over most extended periods. But it has also enjoyed long stretches of outperformance, including during two of the past five decades, suggesting it can act as an effective hedge. What exactly gold hedges against is less clear, however. It is more than just inflation.

The modern history of gold as an investible asset class essentially began in 1971 when the U.S. officially ended the U.S. dollar’s link to gold at a fixed $35 an ounce. Over the course of the 1970s, gold’s price in dollar terms rose more than 10-fold, according to the World Gold Council. That beat consumer prices, which roughly doubled over the decade. Gold also bested stocks, with the S&P 500 posting a 78% total return, including dividends.

But then gold lost more than 20% of its value in both the 1980s and the 1990s. This coincided with two legendary bull markets in stocks, doing serious damage to gold’s reputation.

Then, in the first decade of this century, there was another reversal. The S&P 500, hit first by the bursting of the dot-com bubble, and then by the 2008-09 financial crisis, lost 9% over the decade while gold rallied 275%.

Zooming out, from 1970 through 2023, gold rose at a surprisingly high compound annual rate of 7.5%, though much of that was front-loaded in the 1970s. It has only matched inflation since then. Stocks have trounced the lifeless gold cube, with the S&P 500 posting a 10.6% annual total return from 1970 to 2023, or 11.7% if starting from 1980.

This makes sense. Stocks offer some intrinsic inflation protection, because companies earn revenue that rises along with prices, allowing commensurate increases in profits and dividends. On top of that, stocks benefit from the growth of the real economy, aided by technological advancement and other forces of progress.

But gold’s outperformance in the 1970s and the 2000s wasn’t a fluke. In particular, its rally in the first decade of this century deserves closer examination. Fears of excessively loose monetary policy played a large role, with the Federal Reserve lowering rates to 1% in the wake of the dot-com crash, then going to zero and launching quantitative easing after the financial crisis. But inflation actually remained tame over this period, with the consumer-price index rising at a compound annual rate of just 2.6% a year, including food and energy. That was a slower pace than in any of the prior three decades.

This suggests it was fear of inflation that was driving gold, even if it never materialized. Perhaps it was also fear of a more general nature. Besides the near-collapse of the banking system, this was a decade characterized by war, terrorism and rising political polarization. As James Grant , a prominent gold advocate and editor of Grant’s Interest Rate Observer, noted in a January issue of the financial publication, gold actually reached a peak of nearly $1,900 an ounce in September 2011, after Standard & Poor’s downgraded the U.S. credit rating in the wake of the debt-ceiling fiasco.

That wasn’t itself an inflationary event, but it did damage to the perceived safety of U.S. Treasurys—perhaps the most important store of value in the global financial system. This highlights another, less-appreciated aspect of gold’s attraction. As Grant says, “gold’s prime virtue is that it’s nobody’s liability. It holds no national passport and has no politics.”

When confidence in society and political institutions erodes, the appeal of gold and other precious commodities like diamonds rises as alternative stores of value that aren’t contingent on societal arrangements. They can also be transported in an emergency. Of course as an investor, an actual catastrophe isn’t necessary to profit, with prices getting bid up as concerns grow. Bitcoin and other cryptocurrencies hold a similar appeal, but they are far less tested, less understood and still subject to big regulatory risks.

Now think of our current moment. The Ukraine war rages on, tensions between China and the U.S. are on the rise and a clash over Taiwan can’t be ruled out in the foreseeable future. One of the most contentious presidential elections in U.S. history is approaching, with both sides of the political divide fearing unusually dire consequences should they lose.

A more prosaic explanation for gold’s recent run is that the Fed is expected to start cutting rates this year. As an asset with no yield, gold tends to rise when rates on alternative assets fall. But rates are actually fairly high now—even real rates adjusted for inflation—and would likely remain so even after a few cuts by the Fed.

“Historically the main driver has been real interest rates, but that relationship to gold has completely broken down,” said Giovanni Staunovo , commodity strategist at UBS Global Wealth Management’s Chief Investment Office.

In a recent note, wealth managers at UBS pointed to rising gold purchases by central banks worldwide, which they said have reached the highest levels since the 1960s at more than 1,000 metric tons in each of the past two years. These bets by central banks could be seen as hedges against the dollar as a reserve currency. Especially coming from nations such as China, they could also represent precautions against future sanctions, in anticipation of still more geopolitical disruption.

UBS generally recommends an allocation of around 5% of a diversified portfolio to gold as a risk hedge. In an interview, Grant declined to recommend a specific level, but observed that, “If things really go bad, 5% isn’t going to do you much good.” Regardless, taking into account gold’s historic performance cycles, some allocation to gold looks far from irrational in today’s world.

Gold’s time to shine could be here again. If not, don’t worry: That would probably mean your other investments will be doing just fine.

Write to Aaron Back at aaron.back@wsj.com