Pemex has recorded a net profit in the second quarter, reversing the big losses of a year ago, thanks to higher sales revenues and improved production.

News of the surprising gain came days after credit ratings agency Moody’s downgraded the Mexican state-controlled oil company one notch and deeper into junk territory, mainly due to the poor performance of its refining operations.