Germany's economy contracted in the second quarter, preliminary official data has shown, as the export-oriented country battles global trade and growth headwinds.

Gross domestic product was 0.1% smaller in April-June than the previous three months, federal statistics authority Destatis said. The figures were in line with forecasts from analysts surveyed by Factset.

The shrinkage means former model pupil Germany is now lagging the other largest economies in the eurozone, after the second quarter saw Italy flatline and France grow 0.2%.

As hard data and soft indicators such as surveys of business, investor and consumer sentiment have eroded in recent weeks and months, economists have warned Europe's powerhouse could suffer falling output and even a technical recession - two successive quarters of negative growth.

Destatis said higher spending by private households and the state as well as increased investments helped support the economy at home.

But "foreign trade developments braked economic growth, since exports fell back more sharply than imports compared with the previous quarter," the statisticians added.

Massive export-oriented industries like carmaking, machine tools and chemicals have suffered in Germany as US President Donald Trump has broadened a trade confrontation with China and threatened to open a new front against the European Union.

"With the escalating trade conflicts of the USA, the ever more probable chaos (of) Brexit and the weaker world economy, the perfect storm has been brewing since the summer of last year," said Klaus Borger, an economist at public investment bank KfW.

"The door at least to a technical recession... is wide open," Mr Borger added.