The UK economy contracted 0.2% between April and June, its worst performance since 2012, the Office for National Statistics said.
The surprise contraction came after a boost to economic growth in the first three months of the year because of Brexit stockpiling.
Rob Kent-Smith, head of GDP at the ONS, said manufacturing output fell and the construction sector weakened.
The pound slipped after the data was released, raising fears of a recession.
“Manufacturing output fell back after a strong start to the year, with production brought forward ahead of the UK’s original departure date from the EU,” said Mr Kent-Smith.
He added that “the often-dominant service sector delivered virtually no growth at all”.
Economists had not been forecasting a contraction in the economy in the second quarter but had expected it to stagnate, with the consensus forecast for 0% growth.
The economy had shown 0.5% growth in the first quarter after manufacturers’ stockpiling ahead of Brexit helped to boost output.
The ONS said: “The path of GDP and some of its components has been particularly volatile through the year so far, largely reflecting changes in timing of activity related to the UK’s original planned exit date from the European Union in late March.”
It said the latest figures showed that the increased stock levels had been partly run down in the second quarter and that a number of car manufacturers had brought forward their annual shutdowns to April as part of contingency planning.
Commenting on the figures, TUC General Secretary Frances O’Grady said: “Negative growth at home and weaker growth around the world is a major worry for workers and business.
“The Prime Minister’s toxic threat to crash out of the EU without a deal only adds to the alarm. It damages confidence in the economy, putting people’s jobs at risk.
“No responsible leader would contemplate inflicting such a crisis on the nation.
“The government should protect us from the current dangers by taking no-deal off the table and giving our economy urgent support through investment in public services.”