That was its biggest annual increase since June 2013, the Office for National Statistics said, and was above the median forecast of 2.7 percent in a Reuters poll of economists.
It is also faster than the growth in pay for most people who have suffered a squeeze on their incomes almost without break for a decade.
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 another Reuters poll.
Prime Minister Theresa May, weakened by the loss of her parliamentary majority in the election, has accepted that voters’ patience with austerity is at an end, the Times reported on Tuesday.
Despite the stronger-than-expected consumer price inflation figures, the pound fell slightly after the ONS data, possibly reflecting a slowing of the surge in prices faced by factories which hints at slower inflation ahead for households.
Paul Hollingsworth, an economist with Capital Economics, said he believed the data showed the drop in the pound has fed through into inflation more quickly than expected.
“While we think that CPI inflation will peak at a little above 3 percent before the end of this year, it is likely to drop back fairly quickly in 2018,” he said.
The ONS said one of the main drivers for inflation in May was the increased cost of package holidays abroad for British tourists who have to pay more for 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.
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.