By Tom Fairless

FRANKFURT -- Germany suffered a record economic contraction in the second quarter as measures to slow the pandemic's spread closed businesses and kept consumers at home, but Europe's powerhouse is nonetheless expected to shrink by less and recover faster than other major economies.

Germany's gross domestic product fell 10.1% compared with the previous quarter, the largest decline since comparable records began in 1970, and roughly double its contraction at the nadir of the global financial crisis in 2009, the federal statistics agency said Thursday.

The economy shrank by 34.7% on an annual basis, roughly matching the 32.9% contraction in the U.S. economy over the same period, according to data published by the Commerce Department on Thursday.

Weakness in Germany is ominous for the rest of Europe, and not just because of the country's size, accounting for about a fifth of the European Union's total GDP. German manufacturers are also tightly integrated in the continent, particularly Italy and Eastern Europe. Other European economies including France and Italy are expected to post even deeper contractions when they report second-quarter economic data on Friday.

Still, a host of recent indicators suggest that the German economy is staging a sharp V-shaped recovery, bolstered by aggressive state-support schemes for workers and businesses.

Despite its heavy reliance on global supply chains and foreign demand, Germany has so far managed to limit the coronavirus's economic toll. Its strategy: a relatively light lockdown, strict hygiene measures and testing, and a heavy dose of government spending.

That cocktail of policies will likely help Germany to outperform all other Group of Seven advanced economies, analysts say. The German economy is likely to shrink 4.3% this year and surpass its pre-pandemic size by the end of 2021, according to analysts at JPMorgan. In contrast, the U.S. economy will likely shrink more than 5% this year and still be around 2.5% smaller at the end of 2021 than it was going into the crisis, the analysts said.

"Germany should benefit from more generous fiscal support than elsewhere in the coming months, its low infection rate and strong public-health system, and limited dependence on foreign tourists," said Andrew Kenningham, chief Europe economist at Capital Economics in London.

Germany's exposure to overseas demand via its large exporters makes the nation vulnerable, however, as long as the virus isn't under control around the world. An early recovery in China, Germany's largest trading partner, has helped many German auto manufacturers and high-tech engineering businesses to offset weakness in Europe and North America. But the resurgence in infections across the U.S. in particular is creating headaches for German business executives.

"We see a lot of uncertainty. Look at the market situation in Mexico or the U.S., it could be from one day to another that a car manufacturer will be closed," said Rolf Breidenbach, president and chief executive of Hella GmbH & Co. KGaA, an auto-parts supplier based in northwest Germany.

Hella said this week it plans to cut around 900 jobs in Germany over the next three years to save costs, joining other German auto manufacturers and suppliers that have recently unveiled plans to cut jobs or trim workers' hours.

While China's economy has stabilized, Europe might be facing a second wave of the virus, which would affect the appetite for cars, Mr. Breidenbach told analysts on a call this week.

"We are quite exposed to whatever goes wrong in the U.S., but also in China and East Asia," said Holger Schmieding, chief economist at Hamburg-based Berenberg Bank.

The impact of the pandemic ricocheted through German industries and sectors in the second quarter, from exports to household consumption, the federal statistics agency said, as measures to contain the virus closed stores, restaurants and venues.

Pockets of infection have recently broken out across Germany as vacationers returned home, prompting a plea from public-health officials this week to strictly follow public-hygiene policies.

Germany, among the most open economies in the West, remains highly dependent on trade. Exports are worth around 47% of Germany's GDP, roughly four times the share of the U.S., according to data from the World Bank. That dependence creates risks in the short term relating to rising trade tensions, the absence of a pact on future EU-U.K. trade ties, and a slowdown in China's economy.

Longer term, Germany's car industry -- central to a manufacturing sector that accounts for about a quarter of the economy -- and the country's sprawling capital-goods sector are facing rapid technological change and rising competition.

Still, German consumers and businesses are increasingly optimistic.

Germany, like other European governments, has poured billions of euros into incentives to discourage employers from laying off workers, which appears to be helping consumption.

German retail sales jumped almost 14% in May from the previous month, while industrial production rose around 8% in the same period, the federal statistics agency said this month. The nation's unemployment rate crept up to 4.5% in June from 4.4% the previous month, still close to a record low, the federal statistics agency said Thursday.

"German consumers are leaving the corona shock from the spring of this year more and more behind," market research firm GfK said last week. Its latest survey of around 2,000 consumers found that confidence is fast returning to pre-pandemic levels.

Daimler AG Chairman Ola Källenius said last week that the auto manufacturer was seeing the first signs of a recovery in sales after a sharp drop in the second quarter, especially at its Mercedes-Benz passenger car unit. On Thursday, Volkswagen AG, Germany's largest auto manufacturer, said it expects to report a positive operating profit for 2020 as a whole, even after a 27% decline in vehicle deliveries in the six months through June. In China, sales of its luxury Audi brand rose in the first half of 2020 from a year earlier.

"Due to the positive trend exhibited in our business over the past few weeks and the introduction of numerous attractive models, we look cautiously optimistic to the second half of the year," said Frank Witter, a Volkswagen board member, in a statement.

Write to Tom Fairless at tom.fairless@wsj.com