NEW ORLEANS — Trying to close the books on the worst offshore oil spill in U.S. history, BP agreed Thursday to provide billions of dollars in new money to five Gulf Coast states in a deal the company said would bring its full obligations to an estimated $53.8 billion.

Federal and state government officials touted the record-breaking $18.7 billion agreement as a historic milestone in the Gulf Coast's recovery. The Deepwater Horizon disaster killed 11 rig workers and spewed millions of gallons of crude that stained beaches, coated wildlife and polluted marshes.

BP also gets a valuable return: Much of the payments, to be made over the next 18 years, could be tax-deductible. And by finally providing shareholders with a clearer cost picture, the London-based oil giant will be freer to embark on new ventures.

"This allows us to manage BP as an oil company," BP CEO Bob Dudley said during a conference call. He said BP could launch as many as 20 major new projects by 2020, depending on oil prices.

The Justice Department said Thursday's agreement would be the largest environmental settlement in U.S. history as well as the largest-ever civil settlement with a single entity. Civil claims by the five Gulf states and the federal government were, by far, the largest unresolved piece of BP's financial obligations for the spill.

BP's total spill-related cost estimate also includes roughly $29 billion on response and cleanup expenses and compensation for Gulf Coast businesses and residents.

"It's time for the company to move on," said Brian Youngberg, an energy analyst for Edward Jones. "It's definitely a win for BP. No company can really do well when you have such a big litigation issue hanging over it."

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 didn't 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.

The broad outlines of the deal were described in Thursday's court filing, but a confidentiality order is keeping the fine print under seal. Eventually, there will be a public comment period on the agreement's merits before a federal judge decides whether to accept it, the Justice Department said.

U.S. District Judge Carl Barbier, who presided over a three-phased trial, already found BP grossly negligent in the nearly 134 million-gallon spill.

While analysts praised the announcement, some environmental advocates complained that government officials should have held out for more money.

"If the court approves this proposal, BP will be getting off easy and 'we the people' will not be fully compensated for the natural resource damages that we suffered, and the law requires that the public is made whole for those damages," said Jacqueline Savitz, U.S. vice president for Oceana, a group dedicated to protecting the world's oceans.

Investors pushed BP shares up 5 percent in late afternoon trading. The Fitch rating firm said the deal will "considerably strengthen" BP's credit profile and would likely lead to an upgrade if approved.

By staggering payments over 18 years, the deal would enable BP to pay dividends to shareholders and have enough financial flexibility for future deals and projects. The total is larger than BP had provisioned for, but without a settlement, the company faced still-larger Clean Water Act penalties.

David Uhlmann, a University of Michigan law professor and former chief of the Justice Department's environmental crimes section, said BP's total price tag is "staggering" but includes many tax-deductible costs. "Settlements always involve trade-offs and compromises, and this one is no different," Uhlmann said.

The criminal and civil penalties BP has agreed to pay are not tax-deductible, but restitution and other business expenses often are.

U.S. Attorney General Loretta Lynch said the settlement "would bring lasting benefits to the Gulf region for generations to come." The deal includes $8.1 billion in payments to state and local governments in Alabama, Florida, Louisiana, Mississippi and Texas for natural resource damage. It also includes a $5.5 billion Clean Water Act penalty, most of which the states would share.

Louisiana suffered most of the spill's environmental impact and would get the largest share, about $6.8 billion.

Louisiana Attorney General Buddy Caldwell said litigation could have dragged on for years, delaying the state's recovery. "Today's settlement is a game-changer for Louisiana, its communities and its families," he said.

The agreement only leaves a handful of relatively minor loose ends for BP, including claims by people who either opted out or were not covered by 2012 settlement with private lawyers.

The April 2010 blowout of BP's Macondo well also spawned a federal criminal probe that resulted in manslaughter charges against two rig supervisors whose trial is set for next year.