U.S. producer prices recorded their biggest gain in five months in February as the cost of energy spiked, a government report showed on Thursday, but underlying inflation pressures were contained.

The Labor Department said its seasonally adjusted producer price index increased 0.4 percent last month, quickening from January's 0.1 percent gain.

Economists polled by Reuters had expected prices at farms, factories and refineries to rise 0.5 percent.

Wholesale prices excluding volatile food and energy costs rose 0.2 percent, moderating from January's 0.4 percent increase. While that was in line with economists' expectations, it was the third consecutive month of increases in core PPI.

The Federal Reserve said on Tuesday the recent steep run-up in oil and gasoline prices would push inflation up only temporarily.

Overall produces prices were lifted by a 1.3 percent increase in energy prices after a 0.5 percent drop in January. Food prices dipped 0.1 percent after falling 0.3 percent the prior month.

In the 12 months to February, producer prices increased 3.3 percent, the smallest increase since August 2010, after advancing 4.1 percent in January.

Gasoline prices rose 4.3 percent, the largest gain in five months, after gaining 2.0 percent in February.

Outside food and energy, producer prices were pushed up by pharmaceuticals, which accounted for a third of the increase in core PPI. A rise in prices for civilian aircraft also contributed.

Passenger car prices edged up 0.1 percent after falling 0.8 percent the prior month. Light motor trucks prices fell 0.4 percent after a 0.9 percent rise the prior month.

In the 12 months to February, core producer prices increased 3.0 percent after rising by the same margin the previous month.