Inflation in the U.K. quickened slightly to a new four-decade high in May due to rising energy and food costs, with little prospect of the trend easing in coming months.

The consumer-price index–which measures what consumers pay for goods and services–increased 9.1% in May, its fastest pace since June 1982, up from the 9% annual rate in April, data from the U.K.’s Office for National Statistics showed Wednesday.

Economists surveyed by The Wall Street Journal had expected a 9.2% annual inflation rate.

Inflation pressures remained tied mainly to increases in food and energy prices. “Continued steep food price rises and record high petrol prices were offset by clothing costs rising by less than this time last year and a drop in often fluctuating computer games prices,” the ONS said.

The core price index–which excludes volatile categories such as energy costs and food–rose 5.9% in May on year, down from a 6.2% increase in April.

The Bank of England on June 16 raised its key interest rate by a quarter percentage point for the fifth consecutive time since December to tame price growth. The BoE also said it expects inflation to be more than 9% over the next few months, and to rise to above 11% in October.

Write to Xavier Fontdegloria at xavier.fontdegloria@wsj.com