WASHINGTON (Reuters) - The U.S. economy slowed less than expected in the third quarter as a tariff-related drop in soybean exports was partially offset by the strongest consumer spending in nearly four years, keeping growth on track to hit the Trump administration’s 3 percent target this year.

Gross domestic product increased at a 3.5 percent annualized rate also supported by a surge in inventory investment and solid government spending, the Commerce Department said on Friday in its first estimate of third-quarter GDP growth.

While that was a slowdown from a 4.2 percent pace in the second quarter, it still exceeded the economy’s growth potential, which economists put at about 2 percent. But there were red flags to the economic expansion that is now in its ninth year and the second longest on record.

Business spending stalled and residential investment declined for a third straight quarter, signs that the boost from a $1.5 trillion tax cut was fading and higher interest rates were hurting the housing market.

“There will come a day of reckoning for the economy after the tax cut monies are all gone, but for today Washington really has something to crow about,” said Chris Rupkey, chief economist at MUFG in New York.

Economists polled by Reuters had forecast GDP expanding at a 3.3 percent pace in the third quarter. The fiscal stimulus is part of measures adopted by President Donald Trump’s administration to boost annual growth to 3 percent on a sustainable basis.

Yet the government is also locked in a bitter trade war with China as well as trade disputes with other trade partners and the last quarter’s slowdown mostly reflected the impact of Beijing’s retaliatory tariffs on U.S. exports, including soybeans.

Farmers front-loaded shipments to China before the tariffs took effect in early July, boosting second-quarter growth. Since then, soybean exports have declined every month, increasing the trade deficit. There were also decreases in exports of petroleum and nonautomative capital goods.

Strong domestic demand, however, sucked in imports of consumer goods and motor vehicles. The widening trade gap chopped off 1.78 percentage points from GDP growth in the third quarter. That was the most since the second quarter of 1985 and reversed the 1.22 percentage points contribution in the April-June period.

FILE PHOTO - A trailer is filled with soybeans at a farm in Buda, Illinois, U.S., July 6, 2018. REUTERS/Daniel Acker

The rebound in imports also reflected a rush by businesses to stockpile before U.S. import duties, mostly on Chinese goods, came into effect late in the third quarter.

Imports subtract from GDP growth. But some of the imports likely ended up in warehouses, adding to the stockpile of inventory, which contributed to GDP.

Inventories increased at a $76.3 billion rate after declining at a $36.8 billion pace in the second quarter.

As a result, inventory investment added 2.07 percentage points to GDP growth, the biggest contribution since the first quarter of 2015, after slicing off 1.1 percentage points from output in the second quarter.

ROBUST CONSUMER SPENDING

“Trade policy may also have driven the big swings in net exports and inventories,” said Michael Feroli, an economist at JPMorgan in New York. “This dynamic could continue on into the fourth quarter.”

Excluding the effects of trade and inventories, GDP grew at a 3.1 percent rate in the third quarter compared to a 4.0 percent pace in April-June.

The dollar briefly rose to a two-month high against a basket of currencies on the data.

Stocks on Wall Street were trading lower after Amazon AMZN.O gave a below par holiday-season sales forecast and Google-parent Alphabet GOOGL.O reported quarterly revenue that missed analysts' estimates. U.S. Treasury yields fell.

Solid third-quarter growth is expected to keep the Federal Reserve on course to raise interest rates again in December, despite a recent tightening in financial market conditions brought about by a stock market sell-off and a rise in U.S. Treasury yields.

The Fed raised rates in September for the third time this year and removed a reference to monetary policy remaining “accommodative” from its policy statement.

The GDP report showed the Fed’s preferred inflation gauge, the personal consumption expenditures (PCE) price index excluding food and energy, increased at a 1.6 percent rate in the third quarter. The core PCE price index rose at a 2.1 percent pace in the April-June period.

Growth in consumer spending, which accounts for more than two-thirds of U.S. economic activity, increased at a 4.0 percent rate in the third quarter. That was the fastest pace since the fourth quarter of 2014 and followed a 3.8 percent pace of increase in the second quarter.

Momentum is, however, expected to slow as wage growth remains gradual despite the unemployment rate being at a near 49-year low of 3.7 percent. In addition, the stock market turmoil is seen reducing household wealth.

Business spending on equipment increased at a 0.4 percent rate, the slowest in two years, after rising at a 4.6 percent pace in the second quarter. Businesses are struggling to find workers and the import tariffs are increasing manufacturing costs for companies, such as Caterpillar Inc CAT.N, 3M Co MMM.N and Ford Motor Co F.N.

“It appears most business leaders have become somewhat cautious about the future and are holding off committing to major investment plans,” said Joel Naroff, chief economist at Naroff Economic Advisors in Holland, Pennsylvania.

The housing market contracted at its steepest pace in more than a year in the third quarter, also dimming the economy’s outlook.