Preliminary data released Thursday by the Finance Ministry showed exports rose 6.7 percent in June from a year earlier to 7.1 trillion yen ($62 billion) on strong demand for machinery, food, metals and computers. Imports climbed 2.5 percent to 6.3 trillion yen ($66 billion). The resulting 721.4 billion yen ($6.4 billion) surplus compared with a surplus of 433 billion yen a year earlier.
Japan recorded a deficit of 580.5 billion yen in May.
Exports to the U.S. edged 0.9 percent lower with falling shipments of cars and trucks, while imports fell 2.1 percent, leaving the politically sensitive trade surplus with Japan's second-largest export market after China little changed.
The Trump administration has imposed tariffs this year on imports of steel and aluminum from many countries, including Japan. It is also threatening tariffs on autos and auto parts, drawing criticism from a U.S. auto industry whose supply chains are deeply enmeshed in global trade.
Japan recorded a trade surplus for the six months through June, the fifth straight half-year period of surplus. The surplus with the U.S. was 3.15 trillion yen ($27 billion).
The administration of Prime Minister Shinzo Abe has been striving to diversify Japan's trade. This week Tokyo and the European Union signed a trade deal that will eliminate almost all tariffs on each other's exports.
Meanwhile, a strategy of building up markets for Japanese exports in Asia is paying off, with strong demand for machinery, metals and vehicles. But Japan's imports of electrical machinery and other industrial inputs, food and chemicals fell as the economy has slowed, while rising prices helped push oil and gas imports higher.
"Even if we take a 3-month average, import volumes have been growing at the slowest pace since late-2016 in recent months, which suggests that domestic demand is no longer as vigorous as it was last year," Marcel Thieliant of Capital Economics said in a commentary.
He noted that in seasonally adjusted terms, exports were flat while imports sank more than 5 percent.
Exports to China rose 11 percent on-year in June to nearly 1.4 trillion yen ($12 billion) while imports from China edged less than a percent lower to 1.45 trillion yen ($12.9 billion) as the trade deficit dropped 68 percent.
Copyright 2019 The Associated Press. All rights reserved. This material may not be published, broadcast, rewritten or redistributed.