The blockbuster $18.7 billion oil spill settlement unveiled Thursday between the U.S. government and oil company BP gave the Justice Department what it wanted: the biggest environmental fine ever levied against a corporation. It also gave BP what it needed: a sense of closure after years spent fighting costly and complex courtroom battles over its role in the worst oil spill in U.S. history.

The deal marks a final reckoning for the Deepwater Horizon spill in the Gulf of Mexico, which riveted the nation for months in 2010 as television networks and Web sites continuously showed underwater video of the leak and the Obama administration struggled to respond effectively.

The settlement ends all federal and state government civil suits against BP for its part in the disaster that killed 11 crew members, immolated the huge drilling rig, and leaked roughly 4 million barrels of crude oil into the water.

With Thursday’s announcement, the London-based oil giant said it planned to add $10 billion to the already enormous reserve it had set aside to cover costs related to the spill, bringing the total
by the company’s estimate to $53.8 billion.

Despite the jaw-dropping number, the latest payments will be manageable for the energy behemoth. The settlement allows BP to make payments over 18 years, making the deal easier to swallow and effectively reducing the size of the settlement, after adjusting for interest rates and inflation.

Some environmental organizations criticized the Justice Department agreement, which is still subject to court approval, saying it let the deep-pocketed corporation off too easily for a spill whose environmental costs aren’t yet fully understood. But the costs to BP were not trivial, even given its size.

The company had to sell off assets around the world, and become leaner, in order to defray the expenses from the spill. It ousted its chief executive, Tony Hayward, in 2010. Its survival as a going concern at times looked questionable.

In the aftermath of the spill, BP had a choice: It could fight its liabilities for decades in court, just as Exxon (now Exxon Mobil) did after the 1989 Valdez oil spill off the coast of Alaska. Or it could apologize profusely and open up its wallet, promising to pay any victims who came forward.

During the spill, top executives met with President Obama at the White House and agreed to set up a $20 billion fund to cover cleanup costs and damages.

Later, BP paid out or agreed to pay out billions for a myriad of claims, including more than $7.8 billion to private individuals and companies, such as gulf fishermen and coastal hotels through a New Orleans court, and $4.5 billion to settle criminal charges.

By contrast, Exxon litigated for two decades over the Valdez spill and paid only $1 billion in the end.

“If approved by the court, this settlement would be the largest settlement with a single entity in American history,” Attorney General Loretta E. Lynch said in a statement Thursday. “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.”

Despite the 2010 spill, BP remains one of the largest foreign investors in the United States and one of the most active oil and gas exploration companies in the Gulf of Mexico.

The company has eight rigs operating in the dark, ultra-deep waters of the gulf, more than it had before the disaster.

Bob Dudley, BP’s chief executive, issued a statement calling the deal “a realistic outcome which provides clarity and certainty for all parties.” He said it would provide “a significant income stream over many years for further restoration of natural resources and for losses related to the spill.”

Investors breathed a sigh of relief on Thursday. The company’s stock price jumped more than 5 percent Thursday to $41.30 a share on news of the agreement. That reaction reflects BP’s deep resources; the annual $1 billion payments will be dwarfed by the company’s annual capital expenditures, now running about $20 billion.

After all these years, scientists still don’t know the full environmental impact of the spill, nor is it clear that the oil and gas industry would respond more quickly and effectively if there were another deep-water blowout.

“It’s impossible to say whether the numbers are good or not,” said David Pettit, a senior attorney for the Natural Resources Defense Council, a nonprofit environmental group. “It’s a big number, but we can’t tell if it’s big enough.”

The agreement comes five years and 73 days after the blowout in mile-deep water led to an explosion aboard the Deepwater Horizon. There had never been a blowout at such depths, and initial efforts to shut in the well failed.

The rig sank on April 22, 2010, coming to rest upside down on the muddy floor of the gulf about 1,500 feet from the wellhead.

The Macondo well continued to gush for a total of 87 days, polluting the gulf with millions of barrels of oil — the precise amount became the focus of furious legal battling — before it could be capped by new hardware and shut in.

One key issue in the event’s aftermath was BP’s negligence, especially as various investigators uncovered a series of fateful decisions leading up to the disaster. Last year, U.S. District Court Judge Carl Barbier in New Orleans found BP guilty of “gross negligence.”

The gross negligence finding enabled the federal government to seek to impose higher fines of as much as $4,300 a barrel for the 3.19 million barrels spilled, instead of $1,100 a barrel for cases where gross negligence was not an issue. Barbier was expected to rule on the amount shortly. In the end, a Clean Water Act fine amounted to $1,724 a barrel.

Barbier had also galvanized settlement negotiations on March 30 when he ruled that Alabama could seek economic damages in lawsuits tried before a jury, which would have led to lengthy and most likely costly trials for BP.

But BP’s efforts to quickly tie up claims took longer than anticipated. BP has fought in court to limit its fines under the Clean Water Act and resist what it considers to be spurious claims from individuals who say they were harmed by the spill. It has also sought to distribute blame for the spill among other companies that were involved in the Macondo well, most notably Transocean, the owner of the Deepwater Horizon rig. Transocean and Halliburton paid BP lump sums to settle their liability.

Thursday’s settlement had several key components.

BP will pay $5.5 billion in Clean Water Act penalties, 80 percent of which will go to restoration efforts in five affected gulf states. It will also pay $7.1 billion in natural resource damages and an additional $700 million to respond to environmental damages unknown at the time of the agreement.

BP has also agreed to pay $5.9 billion to settle claims by state and local governments for economic damages suffered as a result of the spill, and a total of $600 million for other claims, including for reimbursement of damage-assessment costs.

As with all such corporate settlements, all payments aside from the $5.5 billion in Clean Water Act fines will be tax-deductible.

The fine print of the deal offers an unusual financial break. BP will owe interest on payments deferred under the settlement but at a rock-bottom rate fixed at less than 1 percent.

“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 Jackie Savitz, vice president for the environmental group Oceana in the United States. “$18.7 billion may sound like a lot of money, and it is, but it pales in comparison to what BP owes.”

This agreement is unlikely to end all legal actions associated with the spill, but it brings to a close the litigation between the company and the most muscular entities involved — the federal and state governments.

Still outstanding are claims associated with the Plaintiffs Steering Committee, a group of lawyers who are pursuing thousands of private claims against BP related to the spill, some of which the company says are far-fetched. A settlement outline has been reached in that case, which is being heard in a federal court in New Orleans, although the final claims were only due June 8. There is also a shareholder class action lawsuit filed in federal court in Houston, alleging BP misled investors about the magnitude of the disaster in 2010.

In addition, the Justice Department is still pursuing claims against Anadarko Petroleum, which owned a minority stake in the Macondo well but which has argued that it does not share liability in the spill.

Correction: An earlier version of this story incorrectly stated that the Supreme Court earlier this week denied a petition by BP to overrule U.S. District Court Judge Carl Barbier’s decision.

Ellen Nakashima contributed to this report.