The margin, a proxy for profitability, rose to $19.1 a barrel in the quarter from $4.5 on average over the same timeframe in 2021.

A high crude price - which Cepsa pegged at 61% higher year-on-year - would normally weigh on refining margins, but tight refined fuel supply pushed refiners to break records in the second quarter.

European major Shell saw its refining margin almost triple to $28 a barrel.

Cepsa's main shareholder, Abu Dhabi sovereign fund Mubadala, and fellow investor Carlyle had considered selling the group's chemicals unit as part of a strategic review, sources told Reuters earlier this year.

The company said it had now completed the review and the "shareholders concluded that the best way forward for the business is for it to remain within the Cepsa group".

(Reporting by Isla Binnie; editing by David Evans)