Sharecast - GDP shrank 0.5% following 0.5% growth in June, and versus consensus expectations of a 0.2% decline.
ONS director of economic statistics Darren Morgan said: "In July, industrial action by healthcare workers and teachers negatively impacted services and it was a weaker month for construction and retail due to the poor weather.
"Manufacturing also fell back following its rebound from the effect of May's extra Bank Holiday.
"A busy schedule of sporting events and increased theme park visits provided a slight boost."
Paul Dales, chief UK economist at Capital Economics, said: "The 0.5% m/m fall in real GDP in July…could possibly mean that the mild recession we have been expecting has begun.
"Even so, with wage growth still uncomfortably strong, we suspect the Bank of England will still raise interest rates one final time next week, from 5.25% to 5.50%."