A Japanese flag flutters in front of a shipping container area, at a port in Tokyo.

Tokyo - Japan's trade deficit for July narrowed 6.6 percent from a year earlier, data showed Wednesday, with exports picking up on rising demand for cars and machinery.

But the shortfall was still worse than market expectations, and analysts said domestic consumption - rather than export demand - was likely to be the key economic driver in the second half of the year.

The trade figures come about a week after fresh data showed the world's number-three economy suffered its biggest quarterly contraction since the 2011 quake and tsunami as an April sales tax rise slammed the brakes on growth.

On Wednesday, Japan's finance ministry said the trade deficit last month came in at 964.0 billion yen (R100.6 billion), down from 1.03 trillion yen a year ago.

The shortfall was still bigger than market expectations of a 700 billion yen deficit, and extended the run of trade shortfalls to a 25th straight month.

Japan's exports in July rose 3.9 percent on-year to 6.19 trillion yen, posting the first rise in three months thanks to robust shipments of automobiles, machinery and electronic equipment.

Imports rose 2.3 percent to 7.15 trillion yen, underpinned by purchases of oil and gas, which have shot up in the wake of the 2011 Fukushima nuclear crisis, when Japan shuttered its nuclear reactors.

“July's trade deficit was larger than expected, and indicates that net trade is unlikely to provide much support to GDP growth in the third quarter,” Capital Economics said in a note.

“However, the recent improvement in external demand suggests that the shortfall will narrow further towards year-end.”

The trade imbalance would likely narrow further as Japan looks to switch some of its atomic reactors back on, it added.

“The partial resumption of nuclear energy generation should reduce fuel imports, albeit only gradually,” the firm said.

“As a result, import volumes should rise only modestly,” it added.

“We still expect the recovery in domestic demand to resume in the second half of the year, but our forecasts foresee that it will take until early next year before domestic spending returns to the levels reached ahead of the sales tax hike.”

Japan raised its sales tax to 8.0 percent from 5.0 percent on April 1, a move aimed at raising more revenue to help pay down one of the world's heaviest public debt burdens.

But economists had warned that the levy increase could derail Prime Minister Shinzo Abe's bid to kickstart the long-laggard economy.

The latest trade figures will likely be a relief for Japanese authorities amid concerns that the yen's plunge since late 2012 has not translated into a big jump in export growth as domestic firms shift production overseas.

On Wednesday, Credit Suisse also said it expected a gradual improvement in the trade balance on the back of stronger export demand.

“That said, the improvement could easily stop in the event of a downward shock to foreign demand and/or a material increase in import prices,” it added in a note.

(Dow Jones Newswires contributed to this article) - Sapa-AFP