* Sells 7.86 percent stake at 20.10 euros per share
* Sale ends long relationship between the two firms
* Repsol shares down 3.7 percent
(Adds shares, analyst comment and background)
MADRID, June 4 (Reuters) - Mexico's national oil company Pemex has sold the bulk of its stake in Spain's Repsol for 2.09 billion euros ($2.9 billion), ending a more than 25 year partnership and freeing up cash to invest in its own energy sector.
Pemex sold 7.86 percent of Repsol to unspecified private investors on Wednesday at 20.10 euros each, a 3.7 percent discount to the Spanish company's closing price on Tuesday, in a placement handled by book runners Citigroup and Deutsche Bank.
The sale comes five days before Mexican President Enrique Pena Nieto makes his first official visit to Spain and as the country opens up its energy sector to private investment for the first time since 1938.
Pemex's exit as one of Repsol's top three shareholders ends a relationship that had become increasingly fractious in recent years, due to disagreements on policies ranging from top management to the handling of Repsol's investments in Argentina.
Shares in Repsol, which were suspended from trading ahead of the announcement, fell 3.7 percent to 20.10 euros, the price of the placement.
However, analysts welcomed the departure of Pemex, saying it should help ease boardroom tensions at Repsol and allow the Spanish group's chairman Antonio Brufau to focus on acquisition plans.
"We believe that this gives Repsol management a free rein to decide on the next strategic steps for the company," Exane BNP Paribas analyst Alejandro Demichelis said.
Repsol has raised $6.3 billion after completing its exit from Argentina and has said it could spend part of the cash on buying exploration and production assets to boost its upstream business.
It will also pay a 1 euro per share special dividend with part of the Argentine proceeds on June 6.
($1 = 0.7342 Euros)
(Editing by Paul Day and David Holmes)