Filling up hasn't been this cheap in a long time. (AP/Rich Pedroncelli)

Rising gas prices helped drive a surge in inflation last month, according to government data released Tuesday, with the cost of goods rising at the fastest pace in three years.

The Labor Department reported that the consumer-price index, a closely watched gauge of inflation, rose 0.4 percent in April compared with the previous month, beating analysts’ expectations. The increase was largely due to a jump in energy prices that included an 8.1 percent spike in gasoline.

Prices rose across a broad array of other sectors as well, albeit not as dramatically. Food prices were up 0.2 percent, and housing and medical services rose 0.3 percent.But the cost of cars and clothing dipped slightly after big gains earlier in the year.

Excluding the volatile food and energy sectors, prices rose a more modest 0.2 percent in April, a measurement economists often refer to as core inflation. Compared with  a year ago, that figure has risen 2.1 percent.

“That confirms the trends we have seen since the start of the year: Inflation has firmed but is not flaring,” said Diane Swonk, head of DS Economics.

The solid data helps bolster the case for the Federal Reserve to raise interest rates at its next meeting in June. The nation’s central bank increased its benchmark rate in December for the first time since the Great Recession amid signs that the long-simmering recovery was gaining steam.

But the Federal Reserve has been on hold since then. Financial markets swung wildly at the start of the year, sparking fears of recession as the outlook for the global economy grew gloomier. Oil prices fell to 12-year lows, and the dollar continued to climb.

Yet the U.S. recovery has so far proved resilient. Hiring has been robust, and the unemployment rate is down to 5 percent, half of its peak of 10 percent after the recession. Meanwhile, oil prices have stabilized, and the rise in the dollar has abated.

The Fed is responsible for keeping prices stable and fostering maximum employment. Although it has made clear progress on the latter goal, the economy has been running below its target of 2 percent inflation for years. Fed officials have long said that they expect inflation to pick up once the effects of the stronger dollar and low oil prices dissipate. Although the central bank relies on separate data to calculate price increases, Wednesday’s report on consumer costs appears to support the central bank’s claim.

“The tone of this inflation report was encouraging,” said Millan L.B. Mulraine, deputy chief U.S. macro strategist for TD Securities. “Outside of the gains in energy prices, the continued firming in underlying core domestic prices suggests that the Fed’s confidence in the inflation outlook over the medium term might be well placed."

There were other encouraging signs released Wednesday that the recovery remains on track. Housing construction picked up in April, with the Commerce Department reporting a 6.6 percent increase in activity. In addition, industrial production rose 0.7 percent, more than analysts had forecast, amid strong improvements in utilities.