The shortfall of exports to imports for Spain, with the eurozone's fourth-biggest economy, fell 48.1 percent last year from the 2012 level.
The outcome was a deficit of €15.9 billion ($21.8 billion), the economy ministry said.
Eurozone countries under pressure over their public finances are focusing on building up efficiency with deep reforms largely to achieve export-led growth, and several of them are showing signs of making progress.
Bailed-out Portugal and Ireland have greatly improved their trade balances, and so has Greece although the latest data showing the first surplus since 1948 suggest that this is now being driven by exports.
Spain exported goods and services worth €234.24 billion, a 5.2-percent rise over 2012 and the highest level since records started being kept in 1971, it added in a statement.
Imports reached €250.19 billion, a 1.3 percent drop over the previous year.
Prime Minister Mariano Rajoy's conservative government is banking on exports to be an engine of recovery for Spain, which crawled out of recession with 0.1-percent economic growth in the third quarter.
It has changed labour rules to give companies more power to cut wages, fire workers or modify their jobs to boost competitiveness and reduce the unemployment rate which hit 26.03 percent at the end of 2013.
Spain's trade balance in March logged its first surplus since 1971, mainly due to a sharp fall in imports driven by falling domestic demand.
In December the trade deficit dropped by 41.4 percent over the same year-ago period to €1.83 billion.