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.