The economy saw a strong start to the year, but growth has faltered in recent months with the conflict in the Middle East having affected some businesses.
The Iran war has pushed up oil and fuel prices, and also disrupted supply chains.
The ONS said firms in a number of sectors had flagged the conflict as affecting activity, including some manufacturing industries, hospitality firms, travel agencies and entertainment companies.
Since hostilities resumed between the US and Iran last week, the price of oil has risen from about $72 a barrel to $84, although it remains well below the peak of around $120 seen earlier this year.
"Today's data confirm that growth remains fragile," said Fergus Jimenez-England, associate economist at the National Institute of Economic and Social Research.
"As energy prices climb once more, all eyes are now on the new prime minister to deliver much-needed stability."
Yael Selfin, chief economist at KPMG, said the warmer weather and World Cup might have boosted consumer spending into June and July, but this "may not be enough to offset weakness across other parts of the economy".
"The recent rise in energy prices, driven by a pick-up in tensions in the Middle East, could pose a risk to the growth outlook, with financial conditions also tightening as a result," Selfin said.
The growth in May "is not a bad welcome gift for incoming PM Andy Burnham", said Paul Dales, chief UK economist at Capital Economics.
"But with higher energy prices still restraining real incomes, he shouldn't get used to it."
Responding to the latest figures, a spokesperson for the Treasury said: "We have the right economic plan which has put the UK in a much stronger position than two years ago with the fastest growth in the G7 in the first quarter and the OECD agreeing that we have restored stability."
But Conservative shadow chancellor Sir Mel Stride said chancellor Rachel Reeves had "failed" in her attempts to boost growth.
"Two years of higher taxes have choked the economy, and now Andy Burnham wants even more taxes to pay for more benefits.
"Starmer and Reeves may be on their way out but the problem isn't just the chancellor, it's the Labour Party."
.png)
1 hour ago
1

















































