Spain's Telefonica SA (TEF) and Portugal Telecom SGPS SA (PT) said Tuesday they had agreed to each sell their 32.18% stakes in their Moroccan telecommunications unit Medi Telecom SA, or Meditel.

Local Meditel shareholders FinanceCom SA, RMA Watanya SA and Fipar Holding, jointly will pay EUR400 million both to Telefonica and to Portugal Telecom, according to filings made to the Spanish and Portuguese stock market regulators.

Portugal Telecom will have an after-tax capital gain of EUR270 million from the sale of its stake, a company press official said.

Telefonica couldn't immediately say what size of gain it had made.

"After a very successful experience in Meditel, Telefonica considers that it is the appropriate time to crystallize the value created throughout this decade in Morocco," Telefonica said in a release, adding that it and Portugal Telecom have been present in the shareholding of Meditel for more than 10 years.

The transaction assumes an enterprise value of EUR1.62 billion for 100% of Meditel, Portugal Telecom said.

Analysts at Banco Portugues de Investimento said the price for each Meditel stake is above BPI's implicit equity valuation of EUR235 million.

Meditel represents 0.3% and 3.7% of BPI's equity valuation for Telefonica and PT, respectively. BPI has an "accumulate" rating and EUR17.59 target price for Telefonica, and a "reduce" rating and EUR7.21 target price for PT.

At 0838 GMT, Telefonica shares were down 0.1% at EUR17.57, while Portugal Telecom was up 1.3% at EUR7.305.

The Moroccan telecommunications regulator still needs to approve the sale.

Telefonica expects the transaction to be completed by the end of the year.

Company Web site: www.telefonica.com

-By Bernd Radowitz, Dow Jones Newswires, 34 913958120, djmadrid@dowjones.com