MADRID - Spain's recession eased in the second quarter, official data showed on Tuesday, raising hopes the eurozone's fourth largest economy may finally be on the road to recovery.

Gross domestic product shrank by 0.1 percent in the three months ending June as booming exports helped to offset weak domestic demand, compared to a 0.5 percent contraction in the first quarter, data from the national statistics institute showed.

The improved data came just days after the country reported that unemployment rate had fallen for the first time in two years. Earlier July, Spain also posted strong export figures that helped narrow its trade deficit sharply.

"The recovery is underway," Spain's secretary of state for the economy, Fernando Jimenez Latorre, said during an interview with radio Onda Cero.

"I think we have left the worst of the crisis behind us and this trend, this change in inflection will be maintained in the coming quarters according to our estimates."

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.

On an annual basis the economy contracted by 1.7 percent in the second quarter following a 2.0 percent decline in the first three months of the year, the statistics institute said in a preliminary report.

Although the contraction was the eighth straight quarterly decline, it was far less than the 0.8 percent drop in the last three months of 2012.

"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," said the institute.

Prime Minister Mariano Rajoy is hoping that growing exports and an upsurge in tourism would lift the country out of 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 euros ($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 employment costs and help make Spanish goods more competitive.

The unemployment rate fell in the second quarter to 26.26 percent from a record 27.16 percent in the first quarter, data released last week showed.

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 in June due to lower increases in medicine and electricity costs.

While the government has hailed the improvements in economic indicators, it was still forecasting a contraction of 1.3 percent in 2013 and only a feeble 0.5 percent rebound in 2014.

The European Commission predicts the Spanish economy will shrink by 1.5 percent this year while the International Monetary Fund forecasts a decline of 1.6 percent.

"While you have to hail the relative improvements, or rather the lower 'depression', the medium and long term perspectives do not allow for one to cry victory," said Jesus Castillo, economist at French investment bank Natixis.

"The labour market continues to destroy jobs in the industrial sector. While the rate of degradation is much less dramatic than during the worst hours of the crisis, the weight of job seekers in the labour force remains at an extraordinarily high level."

Among industrialised countries, only Greece has a higher unemployment rate, Castillo said.

The statistics institute will publish its final figures for the second quarter GDP on August 29.