U.S. stocks rallied to close near their intraday highs for a second straight session Thursday, as China showed signs that measures to stabilize its economy and stock market may be taking hold.

In afternoon trade, stocks made a dramatic turn lower but stormed back in the final hour of trading, repeating a pattern of roller-coaster activity that has come to be a trademark of the past several sessions.

The Dow Jones Industrial Average DJIA, -1.84% rose 369.26 points, or 2.3%, to close at 16,654.77, with all 30 members of the blue-chip index trading higher. Earlier, the Dow was up by as many as 381 points.

Read: The Dow Jones Industrial Average just made history

The S&P 500 SPX, -1.15% finished up 47.15 points, or 2.4% to 1,987.66, after posting a 49-point gain. All 10 of the index’s main sectors traded higher. The Nasdaq Composite COMP, -0.13% climbed 115.17 points, or 2.5% at 4,812.71, after being up by as many as 121 points.

As a result, for the week, the Dow is up 1.2%, the S&P is 0.9% higher, and the Nasdaq is up 2.3%.

The implied volatility on the S&P 500—the so-called “fear index”—as measured by the CBOE Volatility Index VIX, -0.10% fell 14% to 26.10.

A larger-than-expected upward revision to U.S. gross domestic product data, showing that U.S. economy grew at a faster 3.7% in the second quarter, helped lift the spirits of investors that have been unsettled by a spate of volatility. Weekly data on jobless claims, which pointed to continued strength in the labor market, added to the optimism.

“Today’s revision means the U.S. economy is growing faster and [the] consumer spending portion points to a stronger growth in the second half of the year. With this kind of growth, we expect $135 earnings per share by the end of 2016,” said Phil Orlando, chief equity strategist and senior portfolio manager at Federated Investors.

That translates to a 35% rise in the S&P 500 from its current level by the end of 2016, according to Orlando.

Global equity markets rallied following a 5.3% surge in the Shanghai Composite SHCOMP, -1.28% overnight, snapping a losing streak that wiped out nearly a quarter of its value in a week. That jump cheered investors world-wide, as fears about China have been blamed for much of the recent intense selling around the globe.

See: U.S. investors shouldn’t fear China’s slowdown.

Even so, some China watchers are questioning what drove the move and suggest the Chinese government intervened again. Read more: China’s mystery rally

Investors had fled from stocks largely due to a lack of confidence in the Chinese government’s handling of its financial markets, and the perception that the government was spending all its political capital on propping up the stock market rather than investing in its domestic economy, said John Canally, chief economic strategist for LPL Financial.

“They’re clumsy and not used to reacting to markets,” Canally said. “They’re new to this.”

The rally in U.S. stocks implies that investors are treating the recent actions out of China much like they did the 1998 Asian markets crisis, when U.S. stocks sold off initially, then bounced back, Canally said.

On Wednesday, the S&P 500 jumped 3.9% as the Dow surged 619 points. The benchmark S&P stands 8.9% off its May record close, after finishing down 12.4% from that level on Tuesday.

Other markets:Asian markets rebounded, while European stocks SXXP, +0.60% also traded higher.

Crude oil CLV25, settled 10% higher, while gold US:GCZ5 settled slightly lower. The dollar DXY, +0.05% strengthened by 0.7%.

Economic news: The U.S. economy grew at a faster 3.7% annual pace in the second quarter, up from the initial estimate of growth at a 2.3% clip, the Commerce Department said Thursday.

New applications for U.S. unemployment benefits fell by 6,000 to 271,000 in the seven days ended August 22, the first decline after four straight weekly gains.

Pending home sales rose 0.5% in July after an upward revision to June’s numbers, the National Association of Realtors said Thursday.

The weekend will bring the Federal Reserve’s annual conference in Jackson Hole, Wyo., where the central bank might offer fresh clues about a possible interest-rate hike. On the Fed front on Thursday, Kansas City Fed President Esther George said the market turmoil “complicates” any decision to raise rates, but she repeated her long-held call for a rate increase.

Individual movers and shakers: Prominent investor Carl Icahn revealed a roughly 6.8% stake in Freeport-McMoRan, Inc. FCX, -7.94% late Thursday after the company earlier in the day cut its capital spending plans for 2016 by 29% and said it would also eliminate some jobs. Shares jumped nearly 29% to lead the S&P 500 gainers and also popped higher after in after-hours trade when the stake was announced.

Tesla Motors Inc. TSLA, +1.63% shares rallied 8% after Consumer Reports gave the electric car maker’s Model S sedan a 103-point score out of 100.

Tiffany & Co. TIF, -0.90% slumped 2% after its disappointing quarterly earnings report. Dollar General Corp. DG, -2.48% slid 3% following its quarterly results.

.—Victor Reklaitis in London contributed to this article.