BP also set aside $32.2 billion for the cost of the spill, a charge that led to the $17 billion quarterly loss, compared with a profit of $4.39 billion a year earlier. It is the first time in 18 years that the company has been in the red. The charge includes the $20 billion compensation fund the company set up following pressure from President Barack Obama as well as costs to date of $2.9 billion.
But the company also stressed its strong underlying financial position - revenue for the quarter was up 34 percent at $75.8 billion - and Hayward said it had reached a "significant milestone" with the capping of the leaking well.
BP said the decision to replace Hayward, 53, with the company's first ever non-British CEO was made by mutual agreement. In a mark of faith in its outgoing leader, BP said it planned to recommend him for a non-executive board position at its Russian joint venture and will pay him 1.045 million pounds ($1.6 million), a year's salary, in lieu of notice.
"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," BP Chairman Carl-Henric Svanberg said in a statement accompanying the quarterly earnings update.
Svanberg said the April 20 explosion of the Macondo well on the Deepwater Horizon platform run by BP in the Gulf of Mexico has been a "watershed incident" for the company.
"BP remains a strong business with fine assets, excellent people and a vital role to play in meeting the world's energy needs," he said. "But it will be a different company going forward, requiring fresh leadership supported by robust governance and a very engaged board."
Besides permanently plugging the oil leak and cleaning up the spill and the company's image, Dudley will oversee the sale of $30 billion in assets over the next 18 months to bolster the company's finances.
Hayward, who has a Ph.D in geology, had been a well-regarded chief executive. But his promise when he took the job in 2007 to focus "like a laser" on safety came back to haunt him after the explosion on the Deepwater Horizon rig killed 11 workers and unleashed a deep-sea gusher of oil.
He became the lightning rod for anti-BP feeling in the United States and didn't help matters with a series of gaffes, raising hackles by saying "I want my life back," going sailing, and what was viewed as an evasive performance before U.S. congressmen in June.
In a statement on Tuesday, Hayward said it was right that BP embark on its next phase under new leadership.
"The Gulf of Mexico explosion was a terrible tragedy for which - as the man in charge of BP when it happened - I will always feel a deep responsibility, regardless of where blame is ultimately found to lie," he said.
On top of the $1.6 million payout, Hayward retains his rights to shares under a long-term performance program which could eventually be worth several million pounds if BP's share price recovers. The stock, which has lost around 40 percent since the well explosion, was almost flat at 417 pence ($6.45) in early trade on the London Stock Exchange on Tuesday.
Hayward, who will remain on the board until Nov. 30, will also be entitled to draw an annual pension of 600,000 pounds from a pension pot valued at around 11 million pounds.
Svanberg described Dudley, 54, who was thrown out of Russia after a battle with shareholders in the company's TNK-BP joint venture, as a "robust operator in the toughest circumstances."
Currently BP's managing director, Dudley grew up partly in Hattiesburg, Mississippi, and has so far avoided any public missteps. He spent 20 years at Amoco Corp., which merged with BP in 1998, and lost out to Hayward on the CEO slot three years ago.
Dudley will be based in London when he takes up his appointment and will hand over his present duties in the United States to Lamar McKay, the chairman and president of BP America.
Crews were restarting work to plug the leaky Gulf well after the remnants of Tropical Storm Bonnie blew through, forcing a short evacuation. The U.S. government's oil spill chief, Retired Coast Guard Adm. Thad Allen, said Monday that the so-called static kill - in which mud and cement are blasted in from the top of the well - should start Aug. 2.
If all goes well, the final stage - in which mud and cement are blasted in from deep underground - should begin Aug. 7.
BP said the bottom kill could take days or weeks, depending on how well the static kill works, meaning it will be mid-August before the well is plugged for good.
Hayward said the company expects to pay the "substantial majority" of the remaining direct spill response costs by the end of the year.
"Other costs are likely to be spread over a number of years, including any fines and penalties, longer-term remediation, compensation and litigation costs," Hayward said.
BP said the sale of $30 billion in assets over the next 18 months will be "primarily in the upstream business, and selected on the basis that they are worth more to other companies than to BP."
That would leave the company with a smaller, but higher quality Exploration & Production business, it said.
In London, Greenpeace protestors closed more than 50 service stations in a protest timed to coincide with the company's earnings update. The environmental action group is calling on Dudley to focus the company on greener and renewable sources of energy.
Richard Hunter, head of U.K. Equities at Hargreaves Lansdown Stockbrokers, said that significant challenges remain for the company but it is "moving aggressively to position itself for the tough times ahead."
"The triple pronged approach of increased provisions, asset sales and a new CEO should be a potent mix in forming a strong future foundation," Hunter said. "Behind the obvious headlines, the underlying trading performance was robust with a significant improvement having been made on a like for like basis."
The company reported that underlying replacement cost profit - the measure most closely watched by analysts - was $5 billion for the three months between April and June when adjusted for one-off items and accounting effects. That compared favorably with a $2.9 billion profit for the second quarter of 2009.
"Outside the Gulf it is very encouraging that BP's global business has delivered another strong underlying performance, which means that the company is in robust shape to meet its responsibilities in dealing with the human tragedy and oil spill in the Gulf of Mexico," Hayward said.
Higher prices for oil and gas made up for slightly lower output and a loss in gas marketing and trading in Exploration & Production, while Refining & Marketing reported increased profits as a result of strong performance in the fuels value chains and the lubricants and petrochemicals businesses.
The company said it planned to reduce net debt to a range between $10 billion and $15 billion within the next 18 months, compared to net debt of $23 billion at the end of June, to ensure that it had the flexibility to meet its future financial obligations.
Capital spending for 2010 and 2011 will be about $18 billion a year, in line with previous forecasts.