LISBON- Portugal's Galp Energia narrowed its losses in the third quarter and will sell a controlling stake in its natural gas distribution business in Portugal, it said on Monday.

It reported an adjusted net loss of 23 million euros ($27 million) versus a profit of 101 million a year earlier but smaller than its 52 million euro shortfall in the second quarter.

The result was impacted by weaker demand which affected oil and fuel prices, even as Galp's oil output rose 6%.

Galp said it had agreed to sell a 75.01% stake in the gas distribution business for 368 million euros ($435 million) to Allianz Capital Partners.

That equates to around 13 times the estimated EBITDA for 2020 and will reduce Galp's stake to just 2.49%.

The deal, which the company said was "crystallizing value from a non-core asset", should be completed in the first quarter of next year, CEO Carlos Gomes da Silva said on a conference call.

Galp shares were down 3.3% as of 1321 GMT to lag Lisbon's stock index which was off 1.7%.

The firm's refining margin fell to a negative $0.70 per barrel in the quarter from $3.90 a year earlier.

Gomes da Silva said it would maintain its "cautious outlook for the months ahead", underlining refining as a particularly challenging area.

"We'll keep the focus on business optimisation and operational efficiency. In the refining and midstream arena, it's really, really tough, tough times, especially for refining," he said.

Galp suspended production at its largest facility Sines and its smallest, Matosinhos, in April. It resumed output at both locations in June but suspended production at Matosinhos again on October 10. 

This suspension will likely last most of the quarter, the CEO said.

Still, the firm had noticed signs of recovery and booked no material changes to its impairments assessment.

While earnings before interest, taxes, depreciation and amortisation (EBITDA) fell 35% from a year ago to 401 million euros, they rose from the second quarter's 291 million.

"In one of the most difficult years ever for this industry, considering the recent relevant solar acquisition, Galp is almost free cash flow neutral in the first 9 months of 2020," Gomes da Silva said.

The sale of the distribution network to Allianz was meant as an "asset rotation" to compensate for Galp's 325 million euro expenditure in acquiring solar power projects from Spain's ACS ACS.MC , announced in January aimed at making Galp the leading solar power producer in Iberia. 

($1 = 0.8459 euros)

(Reporting by Andrei Khalip, Sergio Goncalves, Victoria Waldersee; editing by David Evans and Jason Neely) ((andrei.khalip@thomsonreuters.com; (351) 213-509-209; Reuters Messaging: andrei.khalip.thomsonreuters.com@reuters.net))