WASHINGTON — The U.S. economy grew at a 2.9 percent rate in the July-September quarter, the strongest pace in two years, as the battered export sector rebounded and businesses finally began restocking their shelves at a faster clip.

The third-quarter gross domestic product, the broadest measure of economic health, was double the 1.4 percent pace in the second quarter, the Commerce Department reported Friday.

GDP growth went into a pronounced slowdown late last year. Exporters were constrained by a rising dollar, which made their products more expensive on overseas markets, and businesses cut back on their inventory rebuilding in the face of weaker sales.

With the dollar stabilizing, export sales rebounded in the summer and businesses picked up the pace of inventory building. Solid growth is also expected this quarter.

The latest growth figure was stronger than the 2.5 percent gain many analysts had been expecting. The GDP report was one of the last major economic reports the government will issue before voters go to the polls on Nov. 8. Republican presidential candidate Donald Trump has cited anemic GDP growth rates as evidence that Democratic economic policies have not worked.

Even with the acceleration in the third quarter, economists believe growth for the entire year will be a lackluster 1.6 percent, reflecting the weak start to the year. The economy grew 2.6 percent for all of 2015. This recovery from the deep 2007-2009 recession has been the weakest in the post-World War II period, with growth averaging just 2.1 percent over the past seven years.

The GDP growth rate in the third quarter was the economy’s best showing since it expanded at a 5 percent rate in the third quarter of 2014. In the final three months of last year, growth slowed to a 0.9 percent rate, followed by weak gains of 0.8 percent in the first quarter this year and 1.4 percent in the second quarter.

Economists expect growth to remain solid in the current October-December quarter, but at a slightly slower pace of around 2 percent.

For the third quarter, much of the rebound reflected growth in exports, which rose at a 10 percent rate. That was the fastest pace since late 2013. A narrowing trade deficit added 0.8 percentage points to growth.

Another major contributor was stronger inventory building, which added 0.6 percentage point to growth after trimming it by 1.2 percentage points in the second quarter.

Consumer spending, which accounts for two-thirds of economic activity grew at a solid 2.1 percent rate but slower than the 4.1 percent spending burst in the second quarter.

Economists believe consumers will continue to support growth in the current quarter and into 2017.

“The consumer should continue to power the economy. The job market is very strong, unemployment is low and wage growth is picking up,” said Mark Zandi, chief economist at Moody’s Analytics. “I don’t see any constraints on the consumer.”