The U.S. economy grew at a faster pace than expected in the first quarter and posted its best growth to start a year in four years.

First-quarter gross domestic product expanded by 3.2%, the Bureau of Economic Analysis said Friday in its initial read of the economy for that period. Economists polled by Dow Jones expected growth of 2.5%. It was the first time since 2015 that first-quarter GDP topped 3%.

"The upside beat was helped by net trade (exports jumped while imports contracted sharply) and inventories which combined contributed almost 170 bps of the rise," wrote Peter Boockvar, chief investment officer at Bleakley Advisory Group. "Personal spending though, the biggest component was up just 1.2%, two tenths more than expected as an increase in spending on services and nondurable goods offset a decline in spending on durable goods."

Exports rose 3.7% in the first quarter, while imports decreased by 3.7%. Economic growth also got a lift from strong investments in intellectual property products. Those investments expanded by 8.6%.

Disposable personal income increased by 3%, while prices increased by 1.3% when excluding food and energy. Overall prices climbed by 0.8% in the first quarter.