(Bloomberg) — BP Plc, the first oil major to report first-quarter earnings, posted a surprise profit as a stronger-than-expected refining and trading performance helped mitigate the lowest crude prices in more than a decade.

Profit adjusted for one-time items and inventory changes totaled $532 million compared with $2.6 billion a year earlier, the London-based company said on Tuesday. Analysts had expected a loss of $244.9 million. BP was the third-biggest gainer in the FTSE 100 Index.

“The company is showing it is restructuring and reducing costs to adjust to oil prices, and that’s pleasing,” said Brendan Warn, a managing director at BMO Capital Markets in London. “Higher-than-expected downstream earnings helped it beat estimates this quarter.”

Chief Executive Officer Bob Dudley, who last month faced a shareholder revolt over his pay package, signaled BP is continuing to drive down costs to ensure it can keep paying dividends. Next year, the company will be able to balance cash flow with shareholder payouts and capital spending at an oil price of $50 to $55 a barrel, down from a previous estimate of $60.

Even so, BP is ready to make even deeper cuts to capital spending if the slump persists, saying it has the option to reduce investment to as little as $15 billion in 2017 from $17 billion this year.

Cheaper Crude

The average price of Brent crude, the global benchmark, slumped to the lowest in almost 12 years in the quarter. While Brent’s decline below $28 a barrel in January cut earnings from production, it made crude cheaper for BP’s refineries. Dudley has also trimmed billions of dollars of spending, cut thousands of jobs and deferred projects to weather the oil-market rout.

The company reported adjusted profit before interest and tax of $1.8 billion from its downstream operations, 16% lower than a year earlier but 49% higher than the preceding quarter. In the upstream business, which includes oil and gas production, BP posted a $747 million loss compared with a $604 million profit a year earlier.

Upstream losses were about 13% lower than expectations, analysts at Exane BNP Paribas said in a note to clients. Downstream earnings were about 60% ahead of analysts’ estimates. About half of the beat in downstream profit came from trading, BP’s Chief Financial Officer Brian Gilvary told analysts on a conference call.

“Lower costs, strong refining operations and an improved supply and trading contribution more than offset the impact of the weaker refining environment and the seasonal reduction in fuels sales,” BP said in the statement.

The company started cutting costs and selling assets following the 2010 oil spill in the Gulf of Mexico. A $20.8-billion settlement related to the spill was approved this month and it “removes uncertainties” for BP, Jon Rigby, a London-based analyst with UBS Group AG, said in a note.

Shares Rise

Oil has rallied since January, rising above $45 as U.S. crude production slows and major producers including Saudi Arabia study a possible cap on output. The increase in prices has pushed up BP’s shares 6.2% this year after a 14% decline in 2015. The stock advanced 4.3% to 375.90 pence in London trading.

“Market fundamentals continue to suggest that the combination of robust demand and weak supply growth will move global oil markets closer into balance by the end of the year,” Dudley said in the statement.

BP’s results are likely to be an indication of how the other oil majors will perform. Total SA is scheduled to publish first-quarter earnings on Wednesday. Exxon Mobil Corp. and Chevron Corp. will announce results on April 29 and Royal Dutch Shell Plc on May 4.