WASHINGTON — The U.S. economy grew at an upgraded annual rate of 3.1 percent in the spring, the fastest pace in more than two years. But growth is expected to slow sharply this quarter in the wake of a string of devastating hurricanes.

The April-June expansion in the gross domestic product — the economy’s total output of goods and services — is up slightly from a 3 percent estimate made a month ago, the Commerce Department reported Thursday. It is the strongest performance since the economy grew at a 3.2 percent pace in the first quarter of 2015. The upward revision reflected larger farm stockpiles.

The year started with a lackluster 1.2 percent gain in the first quarter. Economists believe growth has slowed again to around 2 percent in the current quarter.

The revised figure was the government’s third and final look at GDP for the April-June period, and left GDP rising at an average 2 percent pace over the first six months of the year. That matches the lackluster average annual growth rates seen since the recovery from the Great Recession began in mid-2009.

Analysts have been busy trimming their forecasts for the current July-September quarter to reflect the adverse effects of hurricanes Harvey, Irma and Maria that have hit in recent weeks. But many are optimistic that growth will bounce back quickly as rebuilding gets underway.

Estimates over how much the hurricanes will trim from growth vary from a high of perhaps a 1.7 percentage point reduction in growth this quarter to those who see a smaller impact of around 0.5 percentage point.

Gus Faucher, chief economist at PNC, said he had reduced his third-quarter forecast to 2.7 percent, down by 0.5 percentage point. He noted that various readings on the economy from retail sales to auto sales and industrial production have been weaker since the hurricanes hit but he said the declines have so far been moderate.

While some analysts see third-quarter growth slowing to perhaps 1.5 percent, many believe growth will rebound in the final three months of the year to perhaps as high as 3 percent.

“By the middle of 2018, the economy will be back to its pre-hurricane path,” Faucher predicted.

Economists at Moody’s Analytics have estimated that hurricanes Harvey and Irma will end up costing in total around $167 billion when taking into account property damage and lost economic output. That estimate would put the two storms together close to the total devastation in 2005 caused by Hurricane Katrina, the most expensive natural disaster in U.S. history.

For the whole year, forecasters with the National Association for Business Economics expect the economy will grow a modest 2.2 percent in 2017 and 2.4 percent in 2018.

That would be up from the weak 1.5 percent growth seen in 2016 but it is far below the growth rates of 3 percent or better that President Donald Trump is pledging to produce with his economic program of tax cuts, regulatory relief and tougher enforcement of foreign trade deals.

In the final look at second-quarter GDP, the government said that consumer spending, which accounts for nearly 70 percent of economic activity, grew at a solid 3.3 percent rate in the spring, unchanged from the initial estimate. Business investment in equipment was also unchanged from the previous estimate, posting a solid increase of 8.8 percent at an annual rate.

Trump traveled to Indiana on Wednesday to tout the benefits of the tax plan his administration and congressional Republicans unveiled earlier in the day.

“Our country and our economy cannot take off like they should unless we dramatically reform America’s outdated, complex and extremely burdensome tax code,” Trump told the crowd, urging them to lobby Congress to win passage of the first major revamp of the nation’s tax code in a generation.

The sweeping plan would deeply cut levies for corporations, simplify everyone’s tax brackets and nearly double the standard deduction used by most Americans. However, the measure is expected to face strong opposition from Democrats who contend it is tilted too much to the wealthy and would explode future deficits.