WASHINGTON—The U.S. trade deficit is widening even as the Trump administration pushes Canada, Mexico, China and other countries to recast their economic relations with the U.S.

The Commerce Department said Wednesday that the deficit for the first seven months of the year hit $337.9 billion, up $22 billion from a year earlier to its highest level in a decade. A strong domestic economy is boosting imports while exports are jostled by U.S. trade confrontations and slowing growth abroad.

High-level talks between the U.S. and Canada resumed Wednesday, as part of a Trump administration effort to rewrite the North American Free Trade Agreement. The U.S. has already reached a deal with Mexico, but has strained to resolve differences with Canada over dairy trade, the role of independent tribunals to resolve disputes, and other matters.

“Right now we’re in very intense negotiations” with Canada, Mr. Trump said Wednesday in Washington. “If it doesn’t work out it that’s going to be fine for the country, for our country. It won’t be fine for Canada, but we love Canada.”

Following a morning meeting with U.S. Trade Representative Robert Lighthizer, Canadian Foreign Minister Chrystia Freeland said she was convinced “a deal is possible, and that’s what we are focused on.” She added both sides are exhibiting good will at the negotiations, and the tone is positive.