Japan posted a record 2.82 trillion yen ($19.7 billion) trade deficit in August after higher energy prices and a sharp drop in the yen pushed the value of imports to their highest-ever level, the Finance Ministry said Thursday.

The country's trade deficit has been widening recently and August marked the 13th straight month of red ink, underscoring the impact resource scarcity and heavy dependence on imports have on Japan.

The deficit was larger than the previous record of 2.80 trillion yen seen in January 2014.

Imports surged 49.9 percent to 10.88 trillion yen, the largest increase by value since comparable data became available in 1979, lifted by higher prices for energy sources such as crude oil, coal and liquefied natural gas.

Exports, meanwhile, jumped 22.1 percent to 8.06 trillion yen after shipments of cars and chip-related equipment increased.

"The weaker yen is boosting (the cost of) imports at a time of surging energy prices. Energy and grain prices have shown signs of stabilizing recently, but the impact of the sharp drop in the yen will continue for a while with a lag," said Yuichi Kodama, chief economist at Meiji Yasuda Life Insurance Co.

Russia's war on Ukraine has sent crude oil and other raw material costs surging. The yen's rapid weakening against the U.S. dollar has added to the woes of Japan as it inflates import costs.

The price of imported crude oil roughly doubled from a year earlier to 95,608 yen per kiloliter.

The yen has fallen sharply in recent months. It was down 22.9 percent from a year earlier at 135.08 versus the U.S. dollar in August, according to the ministry data.

It traded in the 143 range on Thursday near a 24-year low, a day after caution grew about direct intervention by the government to prevent a further drop.

"The worry is that China's economy is slowing and the United States is also hit by the double whammy of inflation and rate hikes. This will slow Japanese exports to the major trading partners and the economy, too," Kodama added.

Economists expect the Japanese economy to continue growing in the July-September quarter as the impact of the COVID-19 pandemic wanes, but its pace will likely slow as domestic demand remains weak and accelerating inflation hits households.

Strong external demand has boded well for Japan, boosting exports of cars, auto parts and other equipment. Helped by such items, Japan had a trade surplus of 471.5 billion yen with the United States.

Still, the pace of year-on-year growth was faster for imports than for exports with the United States, 40.5 percent to 1.07 trillion yen and 33.8 percent to 1.54 trillion yen, respectively.

However, with another major trading partner, China, Japan reported a trade deficit of 576.9 billion yen. Imports grew 34.2 percent to 2.19 trillion yen, helped by those of clothes, smartphones and televisions, outpacing a 13.5 percent gain in exports to 1.61 trillion yen, led by hybrid cars, audio equipment and others.

A trade deficit of 130.8 billion yen was reported with the European Union, lifted by cars and lumber.

Imports from the region fell 1.2 percent from a year earlier to 852.6 billion yen, compared with exports that grew 16.7 percent to 721.8 billion yen.