Stocks overcame a big loss on Wall Street Wednesday, though the market’s recovery left plenty of signs of worry among investors that the fallout from the trade war between the U.S. and China will spread.

A late-afternoon rally lifted most of the major stock indexes out of the red, reversing most of the early slide that 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 companies and other sectors.

Even so, the moves in the bond and commodities markets signaled that investors are nervous that the escalating trade war between the U.S. and China may derail the global economy.

Bond yields sank around the world, something that happens when investors see a weaker economy and low inflation on the way. The price of oil tanked and the price of gold shot up to its highest level in six years as traders sought safe-haven holdings.

”You did see buyers come back to the market, which is a good sign for the market in the near term,” said Lindsey Bell, investment strategist with CFRA Research. “Investors need to buckle in for some volatility here in the next couple of months.”

The S&P 500 index eked out a gain of 2.21 points, or 0.1%, to 2,883.98. The index had been down 2% during the heaviest bout of selling.

The Dow dropped 22.45 points, or 0.1%, to 26,007.07. It had been down as much as 589 points.

The Nasdaq led the market’s upward swing, climbing 29.56 points, or 0.4%, to 7,862.83. The Russell 2000 index of smaller companies lost 1.40 points, or 0.1%, to 1,500.69.

The market has been roiled the past couple of weeks by growing anxiety as the U.S. and China clash over trade.

Last week, President Donald Trump rattled markets when he promised to impose 10% tariffs next month on all Chinese imports that haven’t already been hit with tariffs of 25%. China struck back on Monday, allowing its currency, the yuan, to weaken against the U.S. dollar.

China stabilized the yuan on Tuesday and that helped lift U.S. stocks a day after they endured their worst day of the year. But the markets turned volatile again early Wednesday after central banks in New Zealand, India and Thailand cut key interest rates.

The surprise rate cuts triggered a slide in bond yields around the world as investors scrambled for safety.

The yield on the 10-year Treasury touched its lowest level in nearly three years, falling as low as 1.60% from 1.74% late Tuesday, before climbing back to 1.73%. It was above 3% in late November.

Some investors saw the big drops Wednesday morning as an opportunity to buy stocks at cheaper prices.

“I see some stocks that look great that I’m buying today,” said George Young, portfolio manager at Villere & Co. “I just can’t make much of a case for bonds right now.”

The market’s turbulent turn comes less than two weeks after the benchmark S&P 500 hit an all-time high.

While investors have been scrambling to adjust to the turns in the trade conflict, the broader U.S. economy continues to grow and add jobs. Unemployment is at the lowest level in decades and consumer confidence remains strong.

Corporate earnings, meanwhile, have been coming in better than expected.

Still, the bond market continues to flash a warning signal of recession. The gap between the yield on the three-month Treasury and the 10-year Treasury widened further.

It’s a rare occurrence because investors usually demand bigger yields for tying up their money for longer periods of time, and one rule of thumb says a recession may hit about a year afterward if the gap, or spread, between those two rates persists.

A three-month Treasury was yielding 0.28 percentage points more than a 10-year Treasury as of Wednesday afternoon. It was 0.36 points earlier in the day, the widest gap since the spring of 2007, less than a year before the Great Recession.

Investors are increasingly betting that the Federal Reserve will need to cut short-term interest rates to support the economy given all trade tensions, and traders see a nearly 50% chance of three cuts or more by the end of the year. A month ago, they projected that probability at less than 9%.

U.S. stocks have been on a wild ride since Jan. 22, 2018, when Trump first imposed tariffs on solar products and washing machines to help U.S. manufacturers, but they’re virtually back to where they started.

The S&P 500 closed at 2,832.97 that day and has since been down as much as 17% and up as much as 7%, with moves often driven by waxing and waning worries about the trade war. The S&P 500 ended Wednesday up 1.8% from that early 2018 starting point.

Since Trump tweeted in March 2018 that “trade wars are good, and easy to win” after raising tariffs on steel and aluminum, the S&P 500 is up 7.2%, though that gain has nearly halved in the last couple weeks as worries about the trade war have surged.

Banks sustained some of the worst losses Wednesday. Lower bond yields mean lower interest rates on mortgages and other kinds of loans, which mean lower profits for banks. JPMorgan Chase fell 2.2%.

The dimming expectations for global growth also send the price of crude oil down $2.54, or 4.7%, to settle at $51.09 a barrel. Brent crude fell $2.71 to $56.23 a barrel.

Wholesale gasoline fell 7 cents to $1.62 per gallon. Heating oil declined 7 cents to $1.75 per gallon. Natural gas fell 3 cents to $2.08 per 1,000 cubic feet.

Gold rose $34.90 to $1,507.30 per ounce, silver rose 75 cents to $17.16 per ounce and copper rose 2 cents to $2.57 per pound.

The dollar fell to 105.69 Japanese yen from 106.52 yen on Tuesday. The euro strengthened to $1.1234 from $1.1200.

AP Business Writer Damian J. Troise contributed.