The deal seeks to repair the financial hit taken by Repsol when Argentina's President Cristina Kirchner ordered the nationalization of Repsol's 51 per cent stake in YPF in April 2012.
"The agreement reached between the Republic of Argentina and Repsol recognises the company's right to receive $5 billion as compensation for the expropriation of 51 per cent of the shares of YPF," Repsol said in a statement.
The amount is to be paid in Argentine government bonds. The agreement has yet to be approved by Repsol shareholders and the Argentine parliament.
The deal "stipulates guarantees for effective payment as well as the termination of all judicial and arbitration proceedings and the reciprocal waiver of future claims", the statement added.
The expropriation soured relations between Argentina and Spain and sparked international outrage including from Spain's European Union partners.
Kirchner blamed it on Repsol's failure to make agreed investments in the firm. Spain saw it as a blow to its strategic interests.
The nationalization of its subsidiary in Argentina hit Repsol's profits hard in 2013, it said on Tuesday in a separate statement announcing its annual results.
Its net profits slumped by 90 per cent in 2013 to €195 million, it said.
At "constant cost of supply", a measure which Repsol says makes its results comparable to those of US oil companies, it recorded net profits of €1.8 billion, down by 6.7 per cent from the previous year.
Repsol said last week that the expropriation of IPF forced it to make provisions of €1.28 billion in 2013, hitting its financial results.
Settlement of the dispute could help to lure investment to the vast Vaca Muerta shale oil and gas field in Argentina, discovered by YPF in 2010.
It is estimated to contain the equivalent of 22.8 billion barrels of oil, described by Repsol at the time as the largest discovery in its history.