WASHINGTON — President Trump’s trade war is expected to temporarily bolster United States economic growth, in part because Beijing tried to beat the clock on Mr. Trump’s tariffs by stocking up on American soybeans, crude oil and other exports.

Economists are predicting that the gross domestic product for the second quarter could reach 5 percent when the preliminary numbers are released on July 27. The United States trade gap with China has narrowed, as more American products were shipped to Beijing ahead of the tariffs, which went into effect on July 6.

But both effects are expected to be fleeting, and the short-term economic improvement could turn into a long-term loss if both countries follow through with their threats to continue escalating tariffs against each other.

“They will dance, they will sing, they will say, look at the plunge in the trade deficit in the second quarter,” said Ian Shepherdson, chief economist for Pantheon Macroeconomics. “That is of course complete drivel.”