Gross domestic product shrank by 0.5 percent — its eighth straight quarterly decline.
This came after a 0.5-percent drop in the first quarter and a decline of 0.8 percent in the final quarter of 2012, the National Statistics Institute said.
On an annual basis the economy contracted by 1.7 percent following a 2.0 percent decline in the first three months of the year, the institute said in a preliminary report.
"This result was basically caused by a more negative contribution in the domestic demand, which was compensated partially by a positive contribution of the external demand," it said.
Prime Minister Mariano Rajoy is relying on growing exports and an upsurge in tourism to end an economic slump that started in 2008 after the end of a decade-long property boom.
Earlier this month the government reported that Spain's trade deficit narrowed sharply to just €27.5 million ($36 million) in May largely due to booming exports.
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.
The unemployment rate fell for the first time for two years in the second quarter, to 26.26 percent from a record 27.16 percent in the first quarter, the statistics office reported last week.
Seasonal tourism accounted for most of the drop as the sector is expected to be strong this year as cash-strapped Europeans look for budget vacations while avoiding Egypt and other rival destinations in the Middle East and North Africa experience political turmoil.
The statistics agency also reported provisional data showing that inflation slowed in July to 1.9 percent after rising for two months to 2.2 percent and 1.8 percent in May.
While the government has hailed the improvements in economic indicators, it has offered little hope of a solid recovery, forecasting a contraction of 1.3 percent in 2013 and only a feeble 0.5 percent rebound in 2014.
A property market crash in 2008 plunged Spain into a recession, destroyed millions of jobs and left banks awash in bad loans.
The economy emerged gingerly from that downturn in 2010 before sliding back into recession in mid-2011.
The institute will publish its final figures for the second quarter GDP on August 29.