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.
A recession occurs when the economy contracts in two consecutive quarters. This is the first contraction since the fourth quarter of 2012.
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, when the manufacturing sector recorded its biggest quarter rise since the 1980s.
The ONS said GDP had been “particularly volatile” so far this year because of the changes to activity sparked by the original Brexit date of 31 March.
The statistics body said its latest figures showed that those increased stockpiles 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, which also hit growth.