MADRID (Reuters) - Telefonica (>> Telefonica SA) said on Friday it had agreed to buy the 22 percent stake held by Mediaset Espana (>> Mediaset Espana Comunicacion SA) in pay-TV firm Distribuidora de Television (DTS), giving full ownership of the TV firm to the telecoms group.

Spanish media group Prisa (>> Promotora de Informaciones S.A.) in May agreed to sell 56 percent of DTS, known as Canal+ in Spain, to Telefonica, which already held 22 percent of the company.

Mediaset Espana said in a statement the sale of its stake was worth 295 million euros ($402.40 million). It will also receive 30 million euros for giving up its preferential right to acquire Prisa's stake in DTS.

An additional 10 million euros will be paid by Telefonica to Mediaset Espana when the telecoms group closes the acquisition of Prisa's stake and potentially another 30 million euros depending on how many new clients sign up to the pay-TV service over the next four years.

Mediaset Espana said it was also looking at various alternatives to buy back shares in order to compensate shareholders for a capital increase that took place when the stake was bought in 2009.

($1 = 0.7331 Euros)

(Reporting by Julien Toyer, editing by David Evans)