NEW YORK — Investors rode out another turbulent day on Wall Street Thursday that kept stock indexes flipping between gains and losses until a late-day bounce gave the market a modest gain.

Worries about a possible recession collided with hopes that the strongest part of the U.S. economy — shoppers spending at stores and online — can keep going.

The major U.S. stock indexes spent much of the day reacting to big moves in U.S. government bond yields, which fell sharply in the early going, fluctuated for much of the day, and then recovered some of their decline by mid-afternoon.

Stocks in Asia and Europe paved the way for the volatile day on Wall Street early Thursday after China said it would take "necessary countermeasures" if President Donald Trump follows through on a threat to impose tariffs on more than $100 billion of Chinese goods on Sept. 1.

"What you're seeing really is what's been driving the market the last couple of weeks: Trade tensions as well as yield curve stress," said Lindsey Bell, investment strategist at CFRA.

The S&P 500 rose 7 points, or 0.2%, to 2,847.60. The benchmark index swung between a 0.6% gain and 0.5% loss. A day earlier, it plunged 2.9%.

The Dow Jones Industrial Average, coming off its worst day of the year, gained 99.97 points, or 0.4%, to 25,579.39.

Other indexes didn't catch the bounce. The Nasdaq composite dropped 7.32 points, or 0.1%, to 7,766.62, while the Russell 2000 index of smaller companies lost 5.87 points, or 0.4%, to 1,461.65.

Walmart climbed 6.1%, helping to steady the market after it said it made a bigger profit in the last three months than Wall Street expected, thanks in part to strong online sales of groceries. A separate government report also showed that retail sales across the country last month rose more than economists expected.

The yield on the 10-year Treasury was down as low as 1.48% Thursday from 1.58% late Wednesday, another big move.

The yield rose as high as 1.54% by late afternoon, which appeared to put some investors in a buying mood. That yield has been steadily dropping since late last year, when it was above 3%. In late trading Thursday the 10-year yield stood at 1.52%.

The 10-year yield has sunk so much that it dropped below the yield of the two-year Treasury Wednesday, a rare occurrence and one that has historically suggested a recession may be a year or two away.

The 30-year Treasury yield fell to 1.93% from 2.02% and earlier touched a record low, a sign that investors are concerned about how the economy will do in the future. It also recovered some of its decline and stood at 1.96% Thursday afternoon. When investors worry about weaker economic growth and inflation, they tend to pile into Treasurys, which pushes up their prices and in turn pushes down yields.

The trade war isn't the only worry for investors. The United Kingdom's pending exit from the European Union, political unrest in Hong Kong and a totally separate trade war between South Korea and Japan are all adding to the gloom.

The worries have pulled the S&P 500 down 4.5% so far this month, while other markets are down even more sharply. The S&P 500, though, remains within 6% of its record set late last month.

Cisco Systems plunged 8.6% for one of the sharpest losses in the S&P 500 after the technology giant gave a profit forecast that fell short of some analysts' expectations. Technology stocks in the S&P 500 accounted for a big share of the sectors that declined. Gains in shares of companies that sell consumer products tend to hold up in times of economic weakness, which helped drive the market higher.

Besides Walmart's surge, Procter & Gamble rose 1.4% and Coca-Cola gained 1.7%.

General Electric sank 11.3% on news that the industrial conglomerate is being accused of hiding its financial problems by Harry Markopolos, the prominent whistleblower known for outing Bernie Madoff.

In Europe, Germany's DAX sank 0.7%, while France's CAC 40 lost 0.3%. The FTSE 100 in London dropped 1.1%.

Japan's Nikkei 225 fell 1.2%, and the Hang Seng in Hong Kong rose 0.8%.

Commodity prices, which have been swinging sharply on worries that a weaker global economy will dent demand, were lower. Benchmark U.S. crude fell 76 cents to settle at $54.47 per barrel. Brent crude, the international standard, lost $1.25 to close at $58.23.

Wholesale gasoline fell 4 cents to $1.64 per gallon. Heating oil declined 3 cents to $1.81 per gallon. Natural gas fell 9 cents to $2.23 per 1,000 cubic feet.

Gold, which has rallied when worries about the economy have grown, added $3.70 to $1,519.60 per ounce. Silver fell 6 cents to $17.19 per ounce and copper was unchanged at $2.59 per pound.

The dollar rose to 106.11 Japanese yen from 105.88 yen on Wednesday. The euro strengthened to $1.1107 from $1.1137.