The U.S. merchandise-trade deficit widened in August by more than expected to a fresh record as companies raced to replenish depleted stockpiles with imports in the face of firmer demand.

The overall deficit swelled to $82.9 billion from $80.1 billion in July, according to Commerce Department data released Tuesday. The median projection in a Bloomberg survey of economists called for an $81.8 billion shortfall in August. Imports rose by 3.1% to a seven-month high of $201.3 billion while exports increased 2.8% to $118.3 billion.

As states began lifting pandemic-related lockdowns months ago, a prompt rebound in consumer spending against a backdrop of lean stockpiles encouraged companies to import more goods, with the latest data showing rising consumer-goods imports ahead of the holiday shopping season. At the same time, weakness in overseas markets has limited U.S. shipments abroad.

The total value of U.S. two-way goods trade increased to $319.6 billion from $310.5 billion in July, still below pre-pandemic levels as the world gradually recovers from the coronavirus crisis.

The increase in imports was led by a 7% rise in consumer goods, the largest category, while autos, foods and other goods also posted sizable gains. Shipments of industrial supplies, which includes petroleum and petroleum products, fell 4.6% from the prior month.

On the exports side, industrial supplies and foods were the biggest gainers, while shipments of capital goods and autos fell.

The report also showed retail inventories rose 0.8% from the prior month, the second straight increase. Wholesale inventories increased 0.5%, the first rise in four months, mainly on durable goods.