Media playback is unsupported on your device Media caption Chairman Carl-Henric Svanberg: BP still in 'grand shape' despite record losses

BP says it has set aside $32.2bn (£20.8bn) to cover the costs linked to the oil spill in the Gulf of Mexico.

The company said the charge gave it a loss of $17bn for the three months between April and June - a UK record.

BP's chairman said the costs estimate was based on the company's belief that it was not grossly negligent, and added the bill could be higher.

BP also said Bob Dudley, head of the Gulf clean-up operation, will replace Tony Hayward as chief executive

Mr Hayward will leave his post by mutual agreement in October.

He is likely to retain a role within the company. BP plans to nominate him as a non-executive director of its Russian joint venture, TNK-BP.

BP also announced it would increase its asset sales over the next 18 months to $30bn, a total that includes the $7bn-worth earmarked for sale last week.

The $32.2bn cost of the clean-up includes the $20bn already set aside in an escrow account for compensation claims.

"That estimate is also based on our belief that we are not grossly negligent," BP chairman Carl-Henric Svanberg told the BBC's business editor Robert Peston.

"Of course we will not know precisely because it depends on how many claims are coming in and [other] things that could happen."

But he insisted that the company was in good financial shape, with strong cashflow.

"It's of course a huge loss that overshadows everything else, but the underlying performance of the company is actually strong," he told the BBC.

"There is no worry about our financial position and our ability to get through this. It's of course a tragedy and it has large consequences, but we have no doubt that we will be able to rebuild the company," he said.

Stripping out the oil spill costs, BP made a second quarter profit, on a replacement cost basis, of $5bn, compared with $2.9bn for the second quarter of 2009.

'We will change'

MEGA QUARTERLY LOSSES AIG: $61.7bn loss in fourth quarter 2008

AOL Time Warner: $54.2bn loss in first quarter 2002

General Motors: $39bn loss in third quarter 2007

Bob Dudley, currently managing director and a US citizen, told ABC's Good Morning America programme, that BP would become a leaner organisation.

"It will be smaller and financially, it will grow. We're going to learn a lot from this incident and this accident... There's no question that we will change as a company."

The announcements were welcomed by most investors for their clear-cut approach.

Peter Hitchens, of Panmure Gordon stockbrokers, said: "It's basically a kitchen sink job...

"I think it's the board trying to wipe the slate clean."

'Milestone'

It is very difficult to describe a $17bn loss for three months of trading as a sparkling performance. But for BP it could have been a lot worse Robert Peston, BBC business editor Read Robert's blogSend us your comments

Tony Hayward said that, now oil had stopped spilling from the Macondo well, it was a good time to leave his post.

"With the leak now capped, we have reached a significant milestone. This provides a firm basis to reshape the company," he said.

On Monday, the BBC revealed that 53-year old Mr Hayward will receive a year's salary plus benefits, together worth more than £1m.

He will also be entitled to draw an annual pension of £600,000 once he reaches the age of 55.

Mr Hayward's pension pot is valued at about £11m and he will keep his rights to shares under a long-term performance scheme which could - depending on BP's stock market recovery - eventually be worth several million pounds.

Carl-Henric Svanberg said Mr Hayward would be missed.

"The BP board is deeply saddened to lose a CEO whose success over some three years in driving the performance of the company was so widely and deservedly admired," he said.

The handling of the explosion on the drilling rig off Louisiana on 20 April, which killed 11 workers and triggered the worst oil spill in the US, raised questions about Mr Hayward's leadership.