The Commerce Department said on Wednesday the trade gap fell 5.4 percent to $40.6 billion. September's shortfall on the trade balance was revised to $43.0 billion from the previously reported $41.8 billion.
Economists polled by Reuters had expected the trade deficit to narrow to $40.0 billion in October.
When adjusted for inflation, the trade gap fell to $48.3 billion from $51.4 billion the prior month. This measure goes into the calculation of gross domestic product and suggested trade will again contribute to growth this quarter.
The three-month moving average of the trade deficit, which irons out month-to-to month volatility, inched up to $40.9 billion in the three months to October from $40.2 billion in the prior period.
An improving global economy is boosting demand for U.S. exports. In October, exports increased 1.8 percent to $192.7 billion. That was the highest on record and snapped three straight months of declines in exports.
Petroleum exports were the highest on record in October. Exports to China hit a record high as did imports from that country. Still, the trade deficit with China narrowed in October.
China has been one of the fastest-growing markets for U.S. goods, though the pace of export growth slowed in recent months.
Exports to Canada and Mexico also reached all-time highs in October. While exports to the 27-nation European Union rose, they were outpaced by imports, resulting in a record trade deficit.
Overall imports rose a modest 0.4 percent to $233.3 billion in October, the highest in 1-1/2 years. With consumer spending slowing significantly in the third quarter and stocks piling up in warehouses, businesses are probably wary of bringing in too many goods from overseas.
The slowdown in import growth could limit the drag on the economy from an anticipated inventory drawdown in the fourth quarter.