MADRID (Reuters) - Telefonica SA (>> Telefonica SA) gained new customers in Spain at a faster pace in the second quarter, an early sign of a turnaround from a three-year slump that wiped out more than one third of revenue and core profit in its biggest market.

Spain has been the weak spot for Europe's biggest telecoms firm by revenue as cash-strapped consumers cut spending on mobile, internet and television services during a deep recession that ended last year.

However Telefonica's second-quarter results on Thursday showed evidence that recent investments in high-cost fibre optic networks and packages that combine mobile and fixed-line phones, high-speed Internet and TV could be starting to pay off.

The company, which has agreed to buy Prisa's pay-TV business Canal+, said 348,000 new clients had signed to its TV packages in Spain in the second quarter and it had gained mobile subscribers in the country for the first time in three years.

It also said it had now connected 5 million homes to its Spanish fibre network and that the service has 861,000 clients, after new sign-ups increased by 70 percent from the first quarter.

The improvement however came at the expense of lower margins, down 2 percentage points from the first quarter, with some analysts questioning whether Telefonica would eventually benefit from its investment. The margin on operating income before depreciation and amortisation fell to 45.8 pct in the second quarter.

"There is evidence of better commercial traction but domestic competition has intensified, leaving some doubt as to what residual benefits Telefonica might hold on to from its higher investments," Jefferies analysts said in a note to clients.

Revenue in Spain fell 9.1 percent in the second quarter.

However, other analysts were more upbeat and said Telefonica would soon report growth, possibly in the last quarter of this year or the first three months of 2015.

Telefonica shares were down 1.3 percent in afternoon trade, outperforming Spain's blue-chip Ibex index <.IBEX> which fell 2.2 percent.

IMPROVING BUSINESS

The company's underlying business also came closer to stabilising in Germany and improved in Britain, Brazil and the rest of Latin America although depreciating currencies in that region drove down earnings.

Operating income fell 15 percent to 4.13 billion euros (3.25 billion pounds) on revenue down 11.8 percent at 12.73 billion, in line with analysts' forecasts.

Telefonica missed earnings forecasts in the first quarter.

Net profit jumped 4.9 percent to 1.21 billion euros, mainly due to a change in tax accounting in Brazil.

Debt, a major headache for Telefonica in the past, increased by 1 billion euros in the quarter to 43.8 billion euros, still on track for an end-year target of below 43 billion euros.

The debt level, though, does not leave Telefonica much room for manoeuvre in terms of potential purchases in markets such as Mexico, where the group said this week it was in talks over a possible deal that would increase its market share against America Movil (>> America Movil SAB de CV).

($1 = 0.7465 Euros)

(Editing by Erica Billingham)

By Julien Toyer and Andrés González

Stocks treated in this article : Telefonica SA, America Movil SAB de CV