OTTAWA—Canada posted its biggest trade surplus with the U.S. in nearly a decade for July due to higher prices for crude-oil exports and a jump in sales of auto parts and other goods to its fast-growing southern neighbor.

The data, issued by Statistics Canada Wednesday, reinforces the importance of trade with the U.S. to the Canadian economy, and emerges as Ottawa and Washington negotiate updated terms to the North American Free Trade Agreement. President Trump has cited a U.S. trade deficit with Canada as a reason why Nafta...