TOKYO--Japan logged its biggest trade deficit in nearly five years in January, as trade tensions and a global economic slowdown weighed on exports and threatened the country's main engine of growth.

The value of Japan's January exports fell by a faster than-expected 8.4% from a year ago to 5.574 trillion yen, a two-year-low, according to data released by the country's finance ministry on Wednesday.

The country logged its fourth straight monthly trade deficit, which grew by almost 50% to Y1.415 trillion--the biggest since March 2014.

The data underscores the widening impact of the U.S.-China trade dispute on the global economy. Japan--home to many of the world's biggest manufacturers of chip-making tools and smartphone parts--has been hit by lower spending from makers of semiconductors and smartphones amid concerns over weakening demand for electronics world-wide.

Last calendar year, Japan logged its first annual trade deficit in three years.

Japan's exports were also hit by a fall in demand for tankers and cargo ships, as well as flat-rolled steel to China, the ministry said. Exports to China slid by 17% on weak shipments of connectors, display-making equipment, and plastics, exacerbated by a fall in demand ahead of the Lunar New Year, the data showed.

However, Japan's trade surplus with U.S increased 5.1% on year to Y367.4 billion in January.

Japan's overall imports also fell by 0.6%, hurt by both weakening domestic demand as well as falling oil prices, the ministry said.

"We believe its highly likely that weakness in external demand will continue until spring, at the very least," Daiwa Securities Chief Market Economist Mari Iwashita said. "The question for the sluggish Japanese economy is whether its exports and production can recover in the April-June quarter."

Write to Mayumi Negishi at mayumi.negishi@wsj.com