The U.S. Commerce Department released the trade data on Thursday. The U.S. trade deficit narrowed to $41.86 billion in July from a deficit of $45.21 billion in June. June's figure was revised up from a deficit of $43.84 billion.
Analysts had expected a trade deficit of $42.4 billion.
The decline of a deficit was driven by a rise in exports. Exports were by 0.4% in July, while imports decreased by 1.1%.
Exports to Canada were down 8.3%, while exports to China declined by 1.9%.
Imports from China fell 0.2% in July.