Japan posted its biggest trade surplus in over four years in February, thanks to a strengthening in the yen and weak oil prices, though both imports and exports fell, suggesting persisting slack demand both in Japan and overseas.

Preliminary data reported Thursday showed exports fell 4 percent from a year earlier to 5.7 trillion yen ($50.5 billion) in February and imports dropped 14 percent to 5.46 trillion yen ($48.4 billion).

The resulting 242.8 billion yen ($2.2 billion) surplus compares with a deficit of 426 billion yen a year earlier and a deficit of 648.8 billion yen in January. It was the biggest surplus since September 2011.

Surging oil and gas imports following the closures of Japan's nuclear plants after the March 2011 disaster in Fukushima have pushed Japan from perennial surpluses into deficits. A weaker yen accentuated those costs, but the prolonged slump in crude oil prices has alleviated some of the high cost of energy imports.

Japan's imports from the Middle East, the source of most of its oil and gas, fell 35 percent in February from a year earlier. Exports to the United States, its biggest export market, edged up 0.2 percent while imports from the U.S. climbed 5 percent, leaving a trade surplus of 604.1 billion yen ($5.4 billion).

Japan's exports to China rose 5 percent, while its imports from China plunged nearly 21 percent. Japan's deficit with China fell by 50 percent, to 382.4 billion yen ($3.4 billion).

The weakness in overseas demand was spread across industries, as exports of machinery, electronics and chemicals fell, while vehicle exports, which account for a quarter of the total, rose only 0.9 percent.