Japan posted a goods trade surplus of 2.99 trillion yen ($27 billion) in 2017, the second straight year of black ink, as robust exports exceeded imports that surged amid higher energy prices, government data showed Wednesday.

Exports jumped 11.8 percent to 78.29 trillion yen, reflecting an increase in Asia-bound shipments to a record-high value, while imports surged 14.0 percent to 75.30 trillion yen, according to preliminary data from the Finance Ministry.

The country's surplus, however, shrank 25.1 percent from 2016.

For the past year, Japan has seen rising exports on the back of stronger overseas demand for products such as semiconductor manufacturing equipment and cars. This has helped the trade-reliant economy stay in what is widely seen as its second-longest postwar expansion cycle.

But an uptrend in crude oil and other energy prices and the yen's depreciation have boosted the value of imports, weighing on the trade surplus.

The value of crude oil imports to resource-scarce Japan totaled 7.15 trillion yen, up 29.3 percent from a year before to mark the first gain in four years.

Japan ran a trade surplus of 7.04 trillion yen with the United States, logging the first year-on-year increase in two years.

Exports rose 6.8 percent to 15.11 trillion yen and imports gained 10.3 percent to 8.08 trillion yen.

Bilateral trade has become a sensitive issue since U.S. President Donald Trump took office a year ago, pushing an "America First" policy agenda and taking issue with his country's massive trade deficits with major exporters such as Japan and China.

Japan had a 5.93 trillion yen trade surplus with the rest of Asia including China, the world's second-largest economy which grew 6.9 percent in 2017. The surplus with the region expanded 51.8 percent for the third straight year of increase.

Exports to the region gained 15.7 percent to a record 42.93 trillion yen while imports rose 11.4 percent to 36.99 trillion yen.

With China alone, Japan reported a trade deficit of 3.55 trillion yen, down 23.7 percent, following a 20.5 percent surge in exports to a record 14.89 trillion yen and an 8.4 percent gain in imports to 18.44 trillion yen.

Japan's trade deficit with the European Union came to 96.8 billion yen, down 43.0 percent, the ministry data showed.

With the International Monetary Fund projecting 3.9 percent global growth in 2018, the world economy is expected to stay in good shape, supporting Japan's exports.

But economists say movements in crude oil prices and the ability of the Chinese economy to maintain its growth momentum need to be watched closely.

"After strong growth in exports throughout 2017, they will likely remain solid but the pace of growth could slow this year," said Toru Suehiro, senior market economist at Mizuho Securities Co.

"That said, the recent surge in crude oil prices should also take a respite so the trade balance as a whole is expected to remain in the black," Suehiro added.

In December, Japan reported a trade surplus for a seventh straight month at 359.0 billion yen, though it shrank 43.5 percent from a year before as imports gained by a bigger margin than exports in value terms.

Exports saw a 9.3 percent year-on-year rise to 7.30 trillion yen and imports climbed 14.9 percent to 6.94 trillion yen, the ministry said.

The figures were measured on a customs-cleared basis.