The increase came after a fall of 6.9% in March and a record 20.4% decline in April.
In the three months to May, the economy shrank by 19.1% compared with the previous three-month period, the ONS said.
"The economy was still a quarter smaller in May than in February, before the full effects of the pandemic struck," said Jonathan Athow, deputy national statistician for economic statistics at the ONS.
"In the important services sector, we saw some pick-up in retail, which saw record online sales. However, with lockdown restrictions remaining in place, many other services remained in the doldrums, with a number of areas seeing further declines."
Mr Athow told the BBC's Today programme that there could be signs of improvement in next month's release of figures.
"Some of the survey data we're seeing suggests that as more of the economy reopened and as some of the restrictions were eased, we did see stronger performance in June, but it's really early," he said.
"You've got one month of firm data and some indicators suggesting June might be stronger, but there's a long road to go here and we're still trying to figure out what the best data is to understand the overall picture."
May's modest month-on-month expansion came as sectors such as manufacturing, construction, DIY retailers and garden centres were allowed to reopen.
Manufacturing grew by more than 8% during the month, as did construction.
What is GDP?
Gross domestic product (GDP) is the sum (measured in pounds) of the value of goods and services produced in the economy.
But the measurement most people focus on is the percentage change - the growth of the country's economy over a period of time, typically a quarter (three months) or a year. It's been used since the 1940s.
It's the main way of determining the health of the UK economy.
"Today's figures underline the scale of the challenge we face," said Chancellor Rishi Sunak.
"I know people are worried about the security of their jobs and incomes. That's why I set out our Plan for Jobs last week, following the PM's new deal for Britain, to protect, support and create jobs as we safely reopen our economy.
"Our clear plan invests up to £30bn in significant and targeted support to put people's livelihoods at the centre of our national renewal as we emerge through the other side of this crisis."