Growth rebounded from its first-quarter slide to reach 0.5 percent quarter-on-quarter between April and June, according to preliminary data from federal statistics authority Destatis.
Analysts surveyed by data company Factset had predicted expansion would remain at the pace seen between January and March, when growth slowed to 0.4 percent.
“Contrary to the national soccer team, the German economy did not have a rude awakening at the start of the summer,” ING Diba bank analyst Carsten Brzeski said.
The figures showed Europe's largest economy had grown 2.0 percent year-on-year by the end of the second quarter, a result likely to comfort observers who had feared a slowdown throughout 2018 after the weaker first three months.
Germany also outperformed the average of the 19-nation eurozone, whose growth slowed to 0.3 percent between April and June.
Other major economies Italy and France reported below-average expansion.
Growth was lifted by “positive domestic impulses”, Destatis said, with increased spending on consumption by both households and the state.
A major driver of domestic consumption has been the steady decline in unemployment, with monthly official figures regularly announcing new lows not seen since Germany's 1990 reunification.
Workers in some flagship sectors like metalworking have also begun driving harder wage bargains this year, hinting at an end to the long moderation in salaries that followed the financial crisis.
Investments in equipment and construction, helped along by low interest rates, also swelled in the second three months.
But imports grew faster than exports against a background of trade tensions.
The stronger second-quarter growth result was “no all-clear” for the country, said Chambers of Commerce and Industry (DIHK) director Martin Wansleben.
“Trade conflicts are increasingly clouding the international environment,” he said — a major risk for an export-heavy economy like Germany's.
US President Donald Trump's direct faceoff with the European Union has cooled in recent weeks after he and European Commission President Jean-Claude Juncker agreed to talk over transatlantic differences.
It is not clear that Brussels will bend to Trump's demands for what he calls “fair” trade with easier access to the EU for American goods, meaning the showdown is only on ice for the moment.
Meanwhile Germany is also vulnerable to knock-on effects from Washington's confrontation with China, one of the country's biggest trading partners.
And Britain's fast-approaching exit from the European Union threatens to add new hurdles to trade with another major economy.
Indicators of business and investor confidence have fallen back in recent months in response to America and its partners raising tariffs on some goods in a tit-for-tat escalation.
And last week harder data on industrial orders and production in June pointed towards a slowdown.
Nevertheless, “with the economy having grown in 34 out of the last 37 quarters, Germany remains on track for a golden decade,” ING analyst Brzeski said.
But trade tensions, geopolitical risks such as the slump in the Turkish lira and politicians' slowness to invest and reform at home mean “looking ahead, the challenges facing the German economy will increase rather than decrease,” he added.