TOKYO — Japan's exports rose 14.8% in April from a year earlier, marking the eighth consecutive month of growth and shifting the country's trade balance to a surplus of 301.9 billion yen, according to Finance Ministry data. Imports rose 9.7% over the same period, reversing a trade deficit recorded in April of the previous year.

Shipments of semiconductors surged nearly 42% in April from a year earlier, according to Finance Ministry data. Higher exports of medical products, paper goods and electrical machinery also contributed to the stronger export performance.

Exports to China rose 15.5% in April from a year earlier, while exports to the United States rose 9.5%. Imports from China climbed 15%, and imports from the U.S. jumped 23%, according to Finance Ministry data.

The April surplus followed a trade surplus of nearly 643 billion yen recorded in March, according to Finance Ministry data. Oil imports fell nearly 50% in April from a year earlier, and liquefied natural gas imports fell 20% over the same period, according to the ministry. Japan imports almost all of its oil.

The effective closure of the Strait of Hormuz due to the war in Iran has reduced supplies of oil and gas to Japan. The price of Brent crude oil, which traded at about $70 a barrel before the war in Iran, has risen above $100 a barrel. A weakening yen has increased the cost of oil imports denominated in U.S. dollars for Japan.

Shortfalls in oil supplies have pushed domestic prices higher and affected production of oil-related products such as naphtha. Prime Minister Sanae Takaichi ordered the release of some national oil reserves to offset lower supplies.