BP has reached an $18.7bn (£12bn) settlement with the US Department of Justice (DoJ) following the 2010 Gulf of Mexico oil spill.
It comes as a US federal judge was expected to rule on how much BP owed in Clean Water Act penalties following the environmental disaster.
Over 125 million gallons of oil spewed into the Gulf after an explosion at the Deepwater Horizon oil rig in 2010.
The settlement is the largest paid by a single company in US history .
The Deepwater Horizon oil spill was one of the worst environmental disasters in US history and claimed the lives of 11 people.
In December the US Supreme Court rejected the oil giant's legal challenge over an original compensation deal agreed in 2012.
At the time BP had already paid out $2.3bn in so-called business economic loss claims out of a total of $4.25bn in compensation claims to individuals and businesses, according to Patrick Juneau, the administrator appointed by the courts to handle claims.
The settlement process is also separate from other court proceedings relating to the spill, including environmental and criminal penalties.
BP has already set aside $43bn even without the Clean Water Act fine.
US Attorney General Loretta E Lynch said the BP settlement was the largest to be paid by a single company in US history.
"If approved by the court, this settlement would be the largest settlement with a single entity in American history; it would help repair the damage done to the Gulf economy, fisheries, wetlands and wildlife; and it would bring lasting benefits to the Gulf region for generations to come," she said.
In a statement, Bob Dudley, BP's group chief executive, called the settlement a "realistic outcome which provides clarity and certainty for all parties".
"For BP, this agreement will resolve the largest liabilities remaining from the tragic accident and enable BP to focus on safely delivering the energy the world needs."
"For the United States and the Gulf in particular, this agreement will deliver a significant income stream over many years for further restoration of natural resources and for losses related to the spill."
Under the agreement BP will;:
- Pay the US a civil penalty of $5.5bn under the Clean Water Act - over 15 years.
- Pay $7.1bn to the US government and five Gulf states including Florida, Alabama, Mississippi and Louisiana over 15 years for natural resource damages.
- A total of $4.9bn will be paid over 18 years to settle economic and other claims made by the five Gulf Coast states.
- Up to $1bn will be paid to resolve claims made by more than 400 local government entities.
BP said it expected impact of the settlement to be to "increase the cumulative pre-tax charge associated with the Deepwater Horizon accident and spill by around $10bn from $43.8bn at the end of the first quarter".
BP's share price rose 4.6% at 438p following the announcement of the deal.