Imports exceeded exports by 20 per cent or $774 million last month, pushing the annual trade deficit to $1.7 billion, its widest in nearly four years.
That is $900 million more than the trade deficit for the year to June 2013.
Exports at $3.8 billion were 4.8 per cent lower than in July last year which can only partly be explained by a 3.5 per cent rise in the trade-weighted exchange rate over the past year.
Imports at $4.6 billion were up 17 per cent on a year ago.
Last month's imports were boosted by $152 million worth of helicopters, but even excluding aircraft and parts, imports were 11 per cent higher than in July last year, Statistics New Zealand said.
In seasonally adjusted terms exports were down 5.9 per cent last month compared with June. This was despite higher dairy and meat exports - up 13.2 per cent and 3.5 per cent respectively - and a 7.3 per cent increase in exports of mechanical machinery and equipment, which followed a 33 per cent rise in June.
ASB economist Christina Leung said the improvement in manufactured exports was encouraging given the emerging headwinds manufacturers faced, particularly slowing growth in Australia and a higher exchange rate with the Australian dollar.
The main declines in seasonally adjusted exports last month were in crude oil and aluminium, after unusually strong volumes exported in June.
Westpac economist Michael Gordon said: "We expect volatility in the trade figures to continue for the next few months as a number of large movements - think drought and large swings in currencies - throw the balance around."
Dairy prices in recent months had been puzzlingly soft, he said.
The Canterbury rebuild and its associated demand for imports would increasingly dominate the trade balance heading into 2014, Gordon said.
"We expect trade deficits to persist from that point."