Frazzled investors are rushing to buy gold and government bonds as fears of a global recession, sparked by a trade war, grow more real.

U.S. stocks rallied Wednesday as investors shook off early jitters that had briefly pulled the Dow Jones Industrial Average down more than 580 points.

Technology and consumer staples stocks powered much of the gains, offsetting losses in banks, energy and elsewhere.

Bond yields sank around the world, something that happens when investors see a weaker economy and low inflation on the way. Gold prices jumped to the highest price in more than six years.

But the selling began to lose momentum by mid-afternoon.

“(Investors) took the opportunity to buy the dip,” said Lindsey Bell, investment strategist with CFRA Research. “Not saying that we’re out of the woods yet.”

The S&P 500 index closed up slightly. The Dow added 2 points, or less than 0.1%, to 26,032. It was down as much as 589 earlier. The Nasdaq also rebounded from an early slide, gaining 0.5%.

The push into safer investments lifted US gold futures briefly above $1,500 per ounce on Wednesday. US Treasury yields, which move opposite price, collapsed to levels unseen since just before President Donald Trump’s 2016 election.

Warning: Trade war with China could drag on through 2020 presidential campaign

Nervous central banks around the world are slashing interest rates in a bid to blunt the pain from the tariff battle. The central banks of India, New Zealand and Thailand all dropped rates on Wednesday — and all of them acted more emphatically than anticipated.

Taken together, the developments suggest that investors and central bankers are bracing for economic and financial trouble. It’s growing less likely that the United States and China will resolve their conflict soon.

“The longer the tariff uncertainty and escalation goes on, the greater the risk of something bad happening,” said Keith Lerner, chief market strategist at SunTrust Private Wealth.

Searching for safe places to put their money, investors have flocked to gold, which tends to do well during times of uncertainty.

“There is clearly some safe haven bid for gold,” Win Thin, global head of currency strategy at Brown Brothers Harriman, told CNN Business. “But it’s certainly not coming from the inflation hedge angle.”

The VanEck Vectors Gold Miners ETF rose 3% in premarket trading on Wednesday even as the broader stock market retreated.

Bond yields collapse

Another sign of anxiety: A startling rush of money into bonds.

As demand for bonds grew the 10-year Treasury yield took a nosedive on Wednesday, sinking below 1.63%. That means the benchmark rate has been basically cut in half since last fall, reflecting a movement into safe investments and mounting expectations of more easy money from central banks.

Look for bitcoin value to jump to $15,000 after China devalues currency, analyst says

It’s not just a US bond market phenomenon. Germany’s 10-year bond rates tumbled deeper into negative territory, reaching a remarkable -0.6%. That means investors, who usually get interest, are instead paying holders of German bonds to park their money. Government debt in Switzerland and France dropped further into subzero territory as well.

“The drop in yields is getting scary,” Peter Boockvar, chief investment officer at Bleakley Advisory Group, wrote in a note to clients. “The already epic global bond bubble continues to inflate further.”

Trump warns on yield curve

Warning signs are flashing in the yield curve, a reliable recession indicator that measures the gap between short-term and long-term rates. During normal times, longer maturing bonds pay out higher yields than their shorter duration peers. But these aren’t normal times.

The gap between the 3-month and 10-year yields is now the most inverted since 2007.

“And we all know what happened in 2008,” Thin, the Brown Brothers analyst, wrote in a note to clients.

The good news, according to Thin, is that the yield curve inversion was deeper and lasted longer before the Great Recession.

However, he also pointed out that the yield curve had been improving before President Donald Trump unleashed another round of tariffs on China last week.

What crash? Stocks could surge 20%, bullish analyst says

“US recession risks have indeed risen,” Thin said.

Even Trump sounded alarm by the bond market fluctuations.

“Yield curve is at too wide a margin,” Trump tweeted shortly before US markets opened.

The US president urged the Fed to cut interest rates “bigger and faster, and stop their ridiculous quantitative tightening NOW,” referring to the central bank shrinking its balance sheet.