Japan logged its first annual trade deficit in more than 30 years in 2011, calling into question how much longer the country can fund its huge public debt without relying on fickle foreign investors.

The aftermath of the March earthquake raised fuel import costs while slowing global growth and the yen's strength hit exports, data released on Wednesday showed, pushing the trade balance into negative territory.

Few analysts expect Japan to immediately run a deficit in the current account, which includes trade and returns on the country's huge portfolio of investments abroad. A steady inflow of profits and capital gains from overseas still outweighs the trade deficit.

But the trade figures underscore a broader trend of Japan's declining global competitive edge and a rapidly ageing population, compounding the immediate problem of increased reliance on fuel imports due to the loss of nuclear power.

Only four of the country's 54 nuclear power reactors are running due to public safety fears following the March disaster.

What it means is that the time when Japan runs out of savings -- 'Sayonara net creditor country' -- that point is coming closer, said Jesper Koll, head of equities research at JPMorgan in Japan.

It means Japan becomes dependent on global savings to fund its deficit and either the currency weakens or interest rates rise.

That prospect could give added impetus to Prime Minister Yoshihiko Noda's push to double Japan's 5 percent sales tax in two stages by October 2015 to fund the bulging social security costs of a fast-ageing society.

The biggest opposition party, although agreeing with the need for a higher levy, is threatening to block legislation in parliament's upper house in hopes of forcing a general election.

Japan logged a trade deficit of 2.49 trillion yen ($32 billion) for 2011, Ministry of Finance data showed, the first annual deficit since 1980, after the economy was hit by the shock of rising oil prices.

HOLLOWING OUT, AGEING POPULATION

Total exports shrank 2.7 percent last year while imports surged 12.0 percent, reflecting reduced earnings from goods and services and higher spending on crude and fuel oil, pushing annual imports of liquefied natural gas to a record amount.

In a sign of the continuing pain from slowing global growth, exports fell 8.0 percent in December from a year earlier, roughly matching a median market forecast for a 7.9 percent drop, due partly to weak shipments of electronics parts.

Imports rose 8.1 percent in December from a year earlier, in line with a 8.0 percent annual gain expected, bringing the trade balance to a deficit of 205.1 billion yen, against 139.7 billion yen expected. It marked the third straight month of deficits.

Bank of Japan Governor Masaaki Shirakawa said on Tuesday he did not expect trade deficits to become a pattern, and did not foresee the country's current account balance tipping into the red in the near future.

But Japan's days of logging huge trade surpluses may be over as it relies more on fuel imports and manufacturers move production offshore to cope with rising costs and a strong yen, a trend that may weaken the Japanese currency longer term.

A fast-ageing population also means a growing number of elderly Japanese will be running down their savings.

Running a current account deficit would spell trouble for Japan as it means it cannot pay the cost of financing its huge public debt -- already twice the size of its $5 trillion economy -- without overseas funds.

It is likely that we won't be able to rely too much on the sustainability of income surplus because the IS (investment-savings) balance of the Japanese economy is likely to deteriorate. So the current account is likely to diminish around 2016-17, said Junko Nishioka, chief economist at RBS Securities in Tokyo.

Now 96 percent of JGB (Japanese government bond) issuance is digested by domestic investors, but if the current account goes to negative territory, theoretically this means that JGBs are unlikely to be sustainably funded by domestic investors.

(Additional writing by Leika Kihara; Editing by Linda Sieg and Emily Kaiser)