Wall Street's main indexes gained in choppy trading on Wednesday led higher by defensive shares, after Federal Reserve Chair Jerome Powell spoke to the central bank's aim to bring down inflation.

After opening lower, major U.S. indexes erased losses following Powell's testimony before a Senate committee. He said the Fed is "strongly committed" to bringing down inflation that is running at a 40-year high while policymakers are not trying to cause a recession in the process.

Investors had a "slight sigh of relief that Chairman Powell didn't come out any more hawkish than was already established," said Yung-Yu Ma, chief investment strategist at BMO Wealth Management in Dallas.

Investors are trying to assess how far stocks can fall as they weigh risks to the economy with the Fed hiking rates to tamp down surging inflation. The S&P 500 earlier this month fell over 20% from its January all-time high, confirming the common definition of a bear market, with the benchmark index last week logging its biggest weekly percentage drop since March 2020.

"Market sentiment is very negative, so from a contrarian basis that ... makes it harder to knock the market down another level when the level of pessimism is so high," Ma said. "There's some element where a good chunk appears to be priced in until the next round of data comes out."

The Dow Jones Industrial Average rose 98.35 points, or 0.32%, to 30,628.6, the S&P 500 gained 17.42 points, or 0.46%, to 3,782.21 and the Nasdaq Composite added 67.06 points, or 0.61%, to 11,136.36.

Defensive areas real estate, healthcare and utilities led among S&P 500 sectors. Real estate rose 2.5%, healthcare gained 1.9% and utilities added 1.3%.

The energy sector, which has been a strong performer this year, fell 3.5% as oil prices dropped sharply.

Rate-sensitive growth shares outperformed, with the S&P 500 growth index up 0.8%, as the yield on the benchmark 10-year Treasury note moved lower.

"The meaningful move lower in oil has dampened some of the rampant inflation fears ... with the rates moving lower, that's prompted a significant short covering move in technology names across the board," said Michael James, managing director of equity trading at Wedbush Securities in Los Angeles.

In company news, Moderna Inc shares rose 6.1% after the company said an updated version of its COVID-19 vaccine generated a strong immune response against fast-spreading Omicron subvariants.

Dow Inc shares slid 5.2% after Credit Suisse downgraded the chemicals maker's stock to "underperform".

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

The S&P 500 posted 1 new 52-week highs and 38 new lows; the Nasdaq Composite recorded 9 new highs and 168 new lows.