U.S. economic growth was a bit stronger than initially thought in the second quarter, notching its best performance in nearly four years, as businesses boosted spending on software and imports declined.

Gross domestic product increased at a 4.2 percent annualized rate, the Commerce Department said on Wednesday in its second estimate of GDP growth for the April-June quarter. That was slightly up from the 4.1 percent pace of expansion it reported in July and was the fastest rate since the third quarter of 2014.

Businesses spent more on software than previously estimated in the second quarter and the nation also imported less petroleum. Stronger business spending and a smaller import bill offset a small downward revision to consumer spending.

Compared to the second quarter of 2017, the economy grew 2.9 percent instead of the previously reported 2.8 percent. Output expanded 3.2 percent in the first half of 2018, rather than 3.1 percent, putting the economy on track to hit the Trump administration's target of 3 percent annual growth.

But the robust growth in the second quarter is unlikely to be sustained given the one-off drivers such as a $1.5 trillion tax cut package, which provided a jolt to consumer spending after a lackluster first quarter, and a front-loading of soybean exports to China to beat retaliatory trade tariffs.

The government reported on Tuesday that the goods trade deficit jumped 6.3 percent to $72.2 billion in July as a 6.7 percent plunge in food shipments weighed on exports.

While consumer spending has remained strong early in the third quarter, the housing market has weakened further with homebuilding rising less than expected in July and sales of new and previously owned homes declining.