Spain, the eurozone's fourth-biggest economy, posted a trade deficit of just €27.5 million ($36 million) in May as exports rose 7.3 percent from the level a year ago to €20.89 billion.
The biggest exports jumps were in the energy and textile sectors, the finance ministry data showed.
Imports in May meanwhile dipped 2.2 percent to €20.92 billion as orders for iron, steel and paper dwindled.
Exports have been a rare bright spot for the Spanish economy which is struggling to recover from a 2008 property crash that has pushed the jobless rate up to a record 27 percent, saddled banks with a pile of bad loans and caused government debt to soar.
Prime Minister Mariano Rajoy's conservative government has made reforms, such as changes to labour market rules, that have reduced labour costs and help make Spanish goods more competitive.
A trade surplus is a factor of growth in an economy.
Spain posted a trade surplus of €634.9 million in March, its first monthly trade surplus since 1971 as imports slumped because of a collapse in demand due to the economic downturn.