The impact of the fall in the pound since last year's Brexit vote made itself felt as consumer prices increased by 2.9 percent compared with a year earlier and its biggest increase since June 2013, the Office for National Statistics said.
That was above the median forecast for a rise of 2.7 percent in a Reuters poll of economists and is faster than the growth in pay for most people.
The ONS said one of the main drivers for inflation in May was the increased cost of holidays abroad for British tourists who have to pay more their euros and dollars.
Another big push on prices came from computer games and equipment, which are typically imported and therefore reflect the diminished buying power of sterling since the Brexit vote.
Data due to be released on Wednesday is likely to show basic pay rose by an annual 2.0 percent in the three months to April, according to the Reuters poll.
Inflation has picked up speed broadly around the world but in Britain there is extra pressure from the fall in sterling, contributing to a sharp slowdown in British economic growth since the start of this year.
Credit card firm Visa said on Monday it saw the first annual fall in spending by consumers in nearly four years in May.
That was before last week's shock election result that weakened Prime Minister Theresa May and has raised questions about how she will advance her plans to take Britain out of the European Union and other legislation.
Retail price inflation - tracked by British inflation-linked government bonds and many private-sector contracts - rose to 3.7 percent in May, the highest since February 2012.
Despite the sharp rise in prices, the Bank of England is widely expected to keep interest rates at their record low of 0.25 percent when it announces its latest monetary policy decision on Thursday.
The BoE has said it will tolerate inflation above its target of 2 percent because so far there has been no knock-on effect on pay which could generate a longer-lasting inflation problem.
The central bank has previously said it only expected inflation to reach the kind of levels it has now hit at the end of this year.
Some economists have said Britain's political turmoil after the election is likely to make the BoE more cautious about considering a rate hike and could even lead it to revive its massive bond-buying program if the economy weakens further.
The ONS said excluding oil prices and other volatile components such as food, core consumer price inflation rose to 2.6 percent compared with economists' expectations of 2.4 percent.
The ONS said a measure of consumer prices which includes housing costs, the CPIH, edged up to 2.7 percent.
Data on prices paid by factories suggested inflationary pressures in the pipeline might be easing.
Input prices fell by 1.3 percent in month-on-month terms in May, taking the yearly rate of price growth down to 11.6 percent from a downwardly revised 15.6 percent in April.
Growth in prices charged by factories held steady at an annual 3.6 percent, in line with the Reuters poll.
The ONS said house prices in April rose 5.6 percent in annual terms compared with 4.5 percent in March. Prices in London alone rose by 4.7 percent in April.
Enter a name and e-mail address and we will e-mail this website link too them.