NEW YORK (Reuters) - U.S. stocks ended slightly lower on Wednesday, with major indexes giving up gains in choppy trade after the Federal Reserve raised U.S. interest rates, while a strong gain in the energy space helped limit losses.

The Fed raised interest rates and forecast at least two more hikes for 2018, signaling growing confidence that U.S. tax cuts and government spending will boost the economy and inflation and lead to more aggressive future tightening.

The hike was widely expected, and new Fed Chairman Jerome Powell said in a news conference after the rate-hike announcement that the U.S. central bank was trying to take the “middle ground” in raising rates.

“That’s a Fed that really feels good about the economy, not only this year but into next year,” said Jim Paulsen, Chief Investment Strategist at The Leuthold Group in Minneapolis.

“The initial response by equities was to go up because of the confidence the Fed seems to have in the economy. But with bond yields going up in anticipation of more hikes ..., that kind of scared the stock market again.”

Financials .SPSY, which benefit from a higher rate environment, briefly extended gains in the wake of the announcement but lost ground to close down 0.03 percent. Names sensitive to higher rates such as utilities .SPLRCU, down 0.39 percent, and real estate .SPLRCR, off 0.93 percent, were under pressure.

Stocks were choppy following the Fed announcement, as yields on the 10-year U.S. Treasury note US10YT=RR moved closer to 3 percent, touching a one month high of 2.936 percent.

Slideshow ( 7 images )

Stocks have struggled this year while bond yield have moved higher.

(GRAPHIC: S&P 500 vs U.S. 10-Year Treasury Yield - reut.rs/2ptJdIs)

Energy .SPNY jumped 2.63 percent and helped lift equities for a second straight session. Crude oil prices hit a six-week high after a surprise decline in U.S. inventories and as concern persisted over possible disruption to Middle East supply.

Markets participants are still trying to decipher the number of rate hikes this year - whether the Fed will stay at three increases as previously forecast by policy makers, or whether a fourth hike is possible.

The Dow Jones Industrial Average .DJI fell 44.96 points, or 0.18 percent, to end at 24,682.31, the S&P 500 .SPX lost 5.01 points, or 0.18 percent, to 2,711.93 and the Nasdaq Composite .IXIC dropped 19.02 points, or 0.26 percent, to 7,345.29.

Facebook shares gained 0.74 percent to stem its recent sell-off over the past two days, which cost the social media company about $50 billion in market value after reports of data misuse that raised broader questions about consumer privacy and the need for tougher regulation.

Slideshow ( 7 images )

The company chief executive, Mark Zuckerberg, said Facebook “made mistakes” in a statement.

General Mills GIS.N slumped 8.85 percent after the company cut its full-year profit forecast due to higher freight and commodity costs.

That weighed on other food companies, with Kellogg K.N off 3.98 percent, JM Smucker SJM.N down 4.20 percent and ConAgra CAG.N off 2.94 percent.

Southwest Airlines LUV.N fell 4.79 percent after the carrier cut its forecast for a key revenue metric. Other airlines also fell, with the NYSE Arca Airline index .XAL down 1.09 percent.

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

Volume on U.S. exchanges was 6.72 billion shares, compared to the 7.16 billion average over the last 20 trading days.