When adjusted for inflation, the deficit narrowed to $48.2 billion, the lowest since December 2013, from $48.9 billion in June, which could see economists raise their estimates for third quarter gross domestic product.
Trade weighed on growth in the April-June period.
Exports increased 0.9 percent to a record high of $198.0 billion in July, supported by a surge in goods, automobiles, parts and engines, as well as non-petroleum products.
Imports rebounded 0.7 percent in July to $238.6 billion after declining in June. The rebound in imports is a sign of underlying strength in domestic demand.
Read MoreFast-food workers set for arrests at 150 strikes
The increase in imports was driven by food and autos, which both hit record highs.
Petroleum imports declined, which saw the petroleum deficit hitting its lowest level since May 2009. A domestic energy boom has seen the United States reduce its dependence on foreign oil.
The politically sensitive trade gap with China was the highest on record in July.