By Ilan Brat

MADRID--Spanish oil major Repsol SA (REP.MC) said Thursday its second-quarter profit increased 95% on the year, driven by capital gains from the sale of stock in its former Argentinian unit and bonds the company received in compensation for its nationalization.

Repsol said net profit was 520 million euros ($700.1 million) in the quarter, compared with EUR267 million a year ago. In the spring, Repsol settled the legal dispute that arose with Argentina after it nationalized YPF SA (YPF, YPFD.BA) in 2012 and reaped more than $6 billion by selling shares in YPF and compensatory Argentinian government bonds.

However, adjusted net income--a figure that excludes gains or losses in the value of inventories and one-off items--decreased 2.7% to EUR390 million from EUR401 million in the same period a year earlier.

The adjusted result was well above a forecast of EUR279 million based on an average of 34 analysts' estimates compiled by Factset.

Analysts had expected the protests and security concerns that shuttered Repsol's highly profitable main production area in Libya during the quarter to weigh more on its results. Total production decreased 5.8% in the quarter to 338,000 barrels of oil equivalent a day, in part because output that ramped up in Bolivia, Peru and other parts of the world helped offset a lack of output from Libya.

Higher oil and gas prices, as well as profits from the downstream refining and petrochemicals, helped offset lower production.

Write to Ilan Brat at ilan.brat@wsj.com