U.S. producer prices rose a steeper-than-expected 0.5 percent last month as food prices posted their biggest gain in more than 2-1/2 years, but prices outside of food and energy rose just 0.2 percent, the government said on Tuesday.

The rise in the producer price index - a measure of prices received by farms, factories and refineries — outstripped expectations on Wall Street for just a 0.3 percent gain, but the increase in the core index matched forecasts.

Click here to visit FOXBusiness.com's Economy Center.

Food costs shot up 1.4 percent in June, the biggest gain since October 2004, the Labor Department said. Prices for chickens, eggs and fresh fruits and melons were all up sharply.

Energy costs rose 0.7 percent on the back of a 0.4 percent gain in May. Some analysts had expected little change in energy costs.

The rise in June energy prices at the producer level reflected a 6.3 percent jump in gasoline prices, a 6.5 percent gain in home heating oil and a 1.8 percent rise in liquefied petroleum gas. Helping offset those gains, residential natural gas prices skidded 3.7 percent and electricity costs fell a record 2.8 percent.

Prices for cars rose 0.9 percent, the biggest gain since September, while the cost of small trucks and SUVs rose 0.4 percent.

During the first six months of the year, producer prices have risen at just a 2.1 percent annual rate, after a 7.5 percent increase in the second half of last year.

The slowdown reflected a moderation in energy price gains. That moderation, however, could prove short-lived if violence continues unabated in the Middle East.

U.S. crude oil prices, which had been fairly steady over the last two months, hit a record high of $78.40 a barrel on Friday. In overseas trade on Tuesday, U.S. benchmark crude was trading above $76 a barrel.

Rising energy costs have presented a challenge for the U.S. Federal Reserve as it tries to contain the inflationary fallout without damaging the economy.

The U.S. central bank has lifted the bellwether federal funds rate to 5.25 percent from 1 percent in 17 straight quarter-point steps dating to June 2004 and financial markets see about even odds of another hike or a pause at the Fed's next meeting on Aug. 8.

The producer price data come a day ahead of a report on June consumer prices that could sharply alter those expectations.

Core consumer prices have risen an unexpectedly steep 0.3 percent in each of the prior three months, and a similar-sized gain would be seen as sharply boosting odds of a rate increase in August.

In addition, Fed Chairman Ben Bernanke goes before Congress on Wednesday to deliver the central bank's semiannual report on monetary policy, and markets will listen closely for any clues on the Fed's likely course.

Click here to visit FOXBusiness.com's Economy Center.