MADRID/BUENOS AIRES (Reuters) - Spanish oil major Repsol (>> Repsol SA) said on Tuesday its board of directors approved a $5 billion settlement with the government of Argentina, ending a two-year dispute over the seizure of the company's operations in the country.

Though the compensation is half of what Repsol initially demanded after Argentina expropriated its majority stake in energy firm YPF (>> YPF SA), the company has been eager to end a rocky chapter in its history and avoid a drawn-out legal fight.

Argentina hopes the agreement will help it attract foreign investment in the country, which holds one of the world's most promising shale gas and oil formation.

"I think to finally reach a friendly agreement on this contentious issue that has taken two years is extremely positive," Repsol Chairman Antonio Brufau said in a video message that accompanied a statement on the terms of the deal.

YPF President Miguel Galuccio, speaking to reporters in Buenos Aires, praised the deal as a crucial step for Argentina's economy. "YPF is a fundamental tool for the country's energy future and I believe the expropriation has given that tool back to Argentines."

Under the agreement, Repsol will receive a package of three dollar-denominated Argentine sovereign bonds with a nominal value of $5 billion. It will also receive additional bonds for a maximum face value of up to $1 billion to compensate for the market discount on the first group of bonds.

Argentine sovereign bonds mostly trade at a steep discount since the country defaulted on international debt in 2002.

The total market value of the combined packages will be at least $4.67 billion, which could be supplemented by $500 million in back interest payments on one of the bonds, known as the Discount 33.

Repsol can sell the bonds whenever it wants though the final amount it receives for the bonds cannot exceed $5 billion after expenses and interest.

As part of the deal, which follows nearly three months of negotiations in Buenos Aires and still requires approval from Repsol's shareholders and the Argentine Congress, Repsol will drop all lawsuits against Argentina and waive any future legal claims.

After the seizure, Repsol initially sought $10.5 billion in compensation in international arbitration.

"As far as we are concerned, from a financial point of view, we have started a new chapter where we are stronger ... and have enormous enthusiasm," Brufau said.

Argentine President Cristina Fernandez expropiated YPF in a move that stripped Repsol of one-fifth of the Spanish oil giant's annual profit. YPF was created in the 1920s by Argentina's government and privatized in the 1990s.

Fernandez's decision came as Argentina grapples with a chronic energy deficit, with government spending on energy imports rising sharply, putting pressure on state coffers.

For Argentina, putting an end to the Repsol conflict will clear the way for it to pursue foreign investors to develop the Vaca Muerta formation, one of YPF's crown jewels and potentially one of the biggest shale reserves in the Western Hemisphere.

Argentina needs foreign money to develop the field, but international investors, facing legal threats from Repsol, have been reluctant to jump in.

The agreement follows involvement by Spanish and Argentine politicians, and officials in Mexico, whose state-owned oil firm Pemex is Repsol's third largest shareholder. The Mexican company also has close ties with Argentina.

With a deal behind it, Repsol can now focus firmly on a strategic plan to boost its international exploration and production business to compensate for the loss of YPF, which had accounted for over half of its output.

It has said it could sell its 30 percent stake in Spanish power firm Gas Natural Fenosa (>> Gas Natural SDG SA) to help fund a purchase in North America, as well as its remaining 12 percent stake in YPF, worth about $1.8 billion.

Repsol's shares, which have suffered during the turmoil with Argentina, closed up 0.88 percent at 18.37 euros on Tuesday before the deal was announced.

Analysts have said a $5 billion settlement from Argentina could add up to 3 euros to Repsol's share price.

(Additional reporting by Alejandro Lifschitz in Buenos Aires; Editing by Fiona Ortiz and Chizu Nomiyama)

By Tracy Rucinski , Andrés González and Kevin Gray

Stocks treated in this article : Gas Natural SDG SA, Repsol SA, YPF SA