U.S. stocks rose sharply for a second day Thursday as data showing a contraction in the U.S. economy for the second straight quarter raised investor speculation the Federal Reserve may not need to be as aggressive with interest rate hikes as some had thought.

Most S&P 500 sectors gained, with utilities up more than 4%, while the yield on benchmark 10-year Treasury notes retreated.

The decline in yields may suggest "that markets think the Fed will have to pivot and move rates lower at some point, maybe in the next 12 month period," said Mona Mahajan, senior investment strategist at Edward Jones.

"It does imply the pace of tightening will become more gradual going forward."

In addition, the growth forecast for second-quarter earnings has risen this week as more S&P 500 companies have reported results and beaten analysts' expectations. Among them, Ford Motor Co shares rose 5.6% after it reported a better-than-expected quarterly net income.

During the quarter, gross domestic product fell at a 0.9% annualized rate, the U.S. Commerce Department said in its advance GDP estimate. The number exceeded economists' consensus forecast in a Reuters survey for an 0.5% annualized rate.

Two consecutive quarters of declines in growth are traditionally considered a recession, but the private research group which is the official arbiter of U.S. recessions looks at a broad range of indicators, including jobs and spending.

Stocks rallied in the previous session when the Fed raised interest rates as expected and comments by the U.S. central bank's chairman, Jerome Powell, eased some worries about the pace of rate hikes.

The Dow Jones Industrial Average rose 353.33 points, or 1.1%, to 32,550.92; the S&P 500 gained 47.69 points, or 1.19%, to 4,071.3; and the Nasdaq Composite added 111.97 points, or 0.93%, to 12,144.39.

Investors have worried that rising inflation and aggressive Fed rate hikes could at some point tip the economy into a recession.

Among declining stocks, Facebook and Instagram parent Meta Platforms Inc fell about 7% after it posted its first-ever quarterly drop in revenue.

Advancing issues outnumbered declining ones on the NYSE by a 2.97-to-1 ratio; on Nasdaq, a 1.54-to-1 ratio favored advancers.

The S&P 500 posted three new 52-week highs and 31 new lows; the Nasdaq Composite recorded 56 new highs and 90 new lows.