Rising food and gasoline prices lifted U.S. consumer inflation as expected in March, but underlying inflation pressures remained contained, a government report showed on Friday.

The Labor Department said its Consumer Price Index increased 0.5 percent after rising by the same margin in February. That was in line with economists' expectations.

Core CPI -- excluding food and energy - edged up 0.1 percent after gaining 0.2 percent the prior month, and below economists' expectations for a 0.2 percent rise.

The mild rise in core CPI -- which is watched by the Federal Reserve for monetary policy -- is vindication for officials at the U.S. central bank who have viewed the recent energy price spike as having a temporary effect on inflation.

Food and gasoline prices accounted for almost three quarters of the rise in overall consumer inflation last month. Gasoline rose 5.6 percent, increasing for a ninth straight month, and the index has now risen 14.4 percent over the last three months.

Food rose 0.8 percent, the largest gain since July 2008, after increasing 0.6 percent in February.

Core inflation last month was lifted by housing and transportation costs. Shelter costs, which account for about 40 percent of core CPI, rose 0.1 percent, rising by the same margin for a sixth straight month as the recovering economy boosts demand for rental apartments.

There were also increases in new and used vehicle prices, air fares and medical costs. Apparel prices fell 0.5 percent after dropping 0.9 percent in February.

In the 12 months to March, core CPI rose 1.2 percent year-on-year after advancing 1.1 percent in February. Fed officials, however, would like to see that closer to 2 percent. Overall consumer prices rose 2.7 percent year-on-year, the largest gain since December 2009, after increasing 2.1 percent in February.

(Reporting by Lucia Mutikani, Editing by Andrea Ricci)