A federal judge in the US state of Louisiana has granted final approval to an estimated $20bn settlement over the 2010 BP oil spill in the Gulf of Mexico, resolving years of litigation over what caused one of the biggest ever environmental disasters.

The settlement, first announced in July last year, includes $5.5bn in civil Clean Water Act penalties and billions more to cover environmental damage and other claims by the five US states along the Gulf coast, including Texas, Mississippi, Alabama, Florida and Louisiana.

The money is to be paid out over roughly 16 years for what has been called the biggest accidental marine oil spill in the history of the petroleum industry.

The US Justice Department has estimated that the settlement will cost the oil giant as much as $20.8bn, the largest environmental settlement in US history as well as the largest ever civil settlement with a single entity.

US District Judge Carl Barbier, who approved the settlement, had set the stage with an earlier ruling that BP had been "grossly negligent" in the offshore rig explosion which killed 11 workers and caused a 134-million-gallon spill.

In 2012, BP reached a similar settlement agreement with private attorneys for businesses and residents who claim the spill cost them money.

That deal, which did not have a cap, led to a protracted court battle over subsequent payouts to businesses. A court-supervised claims administrator is still processing many of these claims.

BP has estimated that its costs related to the spill, including its initial cleanup work and the various settlements and criminal and civil penalties, will exceed $53bn.

"We are pleased that the Court has entered the Consent Decree, finalising the historic settlement announced last July," BP spokesman Geoff Morrell said in an email.

US Attorney General Loretta Lynch praised the settlement.

"Today's action holds BP accountable with the largest environmental penalty of all time while launching one of the most extensive environmental restoration efforts ever undertaken," Lynch said in a statement.

READ MORE: Gulf ecosystem in crisis after BP spill

In Louisiana, where delicate coastal marshes were damaged by the oil, Governor John Bel Edwards said the decision clears the way for the state to receive critical coastal restoration funding. Alabama Attorney General Luther Strange, who acted as a coordinating lawyer for the five Gulf states, also was among those touting the settlement.

David Uhlmann, a University of Michigan law professor and former chief of the Justice Department's environmental crimes section, said Barbier's ruling "ends a long, sad chapter in American environmental history.

"The question that remains is whether we have learned enough from this tragedy to prevent similar environmental disasters in the future," he said.

While overall reaction to the settlement has been positive, there were lingering complaints that some of the BP payments may be tax-deductible for the oil giant. Court documents state that the civil penalties will not be tax-deductible, although other settlement costs could be.

"We are saddened to learn that the gross negligence of BP continues to enjoy taxpayer subsidies," Lukas Ross of Friends of the Earth said in an emailed news release.