Gross domestic product (GDP) fell by 0.1% during the three months to the end of June, the Office for National Statistics (ONS) said.
It is a big step down from the first quarter of the year, when GDP rose 0.8%.
The service sector was particularly badly hit, falling by 0.4% over the quarter, ONS experts said. A large part of this was in health and social work, and came as less money was spent on the fight against Covid-19.
GDP fell 0.6% in June, and the ONS revised its May estimate from growth of 0.5% to just 0.4%.
ONS director of economic statistics Darren Morgan said: “With May’s growth revised down a little and June showing a notable fall, overall the economy shrank slightly in the second quarter.
“Health was the biggest reason the economy contracted as both the test and trace and vaccine programmes were wound down, while many retailers also had a tough quarter.
“These were partially offset by growth in hotels, bars, hairdressers and outdoor events across the quarter, partly as a result of people celebrating the Platinum Jubilee.”
The Bank of England has warned that the UK might enter recession later this year.