BP, the federal government and five states have reached a tentative settlement over economic and environmental damages from the 2010 Deepwater Horizon disaster, a record $18.7 billion deal that will steer much-needed resources into coastal restoration and help replenish cash-strapped local and state coffers across the Gulf Coast.

Louisiana is set to receive $6.8 billion, the largest piece among the five states. That includes $5 billion to be spent repairing the disaster’s toll on natural resources, money that will largely go to coastal restoration and repairing wetlands and damaged wildlife habitats.

Another $1 billion will be used to cover the state’s economic losses from the spill. The state also will receive $787 million of BP’s Clean Water Act penalties, which also is expected to be used to repair natural resources.

Apart from the $6.8 billion apportioned directly to Louisiana, the deal also calls for up to $1 billion to be spent resolving loss claims with local governments across the Gulf Coast, including those in the Pelican State.

More than 500 lawsuits for damages were filed by local governments, sheriffs, school boards and taxing districts across the region, seeking compensation for lost resources and tax revenue. Those figures are expected to be finalized in coming weeks.

The tentative deal, still awaiting a federal judge’s approval, largely ends a five-year legal battle that’s played out in New Orleans courtrooms in the wake of the April 20, 2010, blowout, which killed 11 men and spilled millions of barrels of crude into the Gulf of Mexico.

Louisiana Attorney General Buddy Caldwell announced the deal during a news conference Thursday morning in Baton Rouge; simultaneous announcements took place in the other states.

The agreement ends years of litigation pursued by the federal government and the five states with coastline along the Gulf: Texas, Louisiana, Mississippi, Alabama and Florida.

Under the settlement, Florida will get $3.25 billion; Alabama, $2.3 billion; Mississippi, $2.2 billion; and Texas, $788 million. Some of the money isn’t assigned to a particular state.

Officials hailed the deal, saying it might give Louisiana some needed momentum in pursuing a $50 billion coastal restoration plan.

“Today is a day that presents an opportunity,” said Chip Kline, chairman of the state Coastal Protection and Restoration Authority. “We must be responsible and make wise decisions on how this money is used.”

Money that Louisiana receives for economic losses will replenish money that was taken from the state’s rainy-day trust fund after the disaster. But how the rest of the settlement can be spent is mostly directed by law, officials said.

The lion’s share of the money will be paid over the next 15 to 18 years; BP will pay the bulk of its claims at an average rate of about $1.1 billion a year.

Legal experts and industry analysts said the deal offered something for both sides and fell within an expected range. Wall Street responded favorably to the settlement: BP shares were up more than 5 percent Thursday, closing the day at $41.29.

“I think it was a win” for the oil giant, said Brian Youngberg, an analyst with Edward Jones & Co. in St. Louis who follows BP.

“Look, the cash that this company generates, most years, it’s going to be north of $30 billion,” he said. “They invest $20 to $25 billion back into the business, and then they pay a healthy dividend. One billion dollars sounds like a lot of money, but for a company the size of BP, it’s very manageable.”

Part of the settlement calls for BP to pay $5.5 billion to resolve its penalties for violating the federal Clean Water Act. That’s about 40 percent of the $13.7 billion the company could have been forced to pay if U.S. District Judge Carl Barbier imposed the maximum penalty in the pending court case.

Environmental groups offered a mixed reaction to that aspect of the deal.

After earlier talks fizzled out, BP likely figured its time to cut a deal was running out. This week, the U.S. Supreme Court declined to hear the company’s appeal to allow some oil spill fines to be shifted to a drilling partner, the latest of countless federal appeals the company has made since the sprawling litigation began.

Many legal experts and others who have followed the case expected Barbier to issue a ruling soon on how much BP would have to pay, culminating a three-phase federal trial that began in 2013. This year, Barbier, who is overseeing the litigation tied to the spill, made the second of two court rulings that set the stage for a multibillion-dollar fine against BP.

From the trial’s first phase, which included eight weeks of testimony to determine responsibility for the spill, Barbier ruled that BP’s conduct ahead of the accident was “reckless,” which opened the company up to elevated Clean Water Act penalties of up to $4,300 per barrel of oil that spilled.

After its second phase wrapped up last year, Barbier determined that 3.19 million barrels of oil were released during the 87-day oil spill, the midpoint between a higher estimate offered by the federal government and a lower one from BP.

Most legal experts who have followed the legal fallout from the spill did not expect the oil giant to get hit with the maximum penalty. But they surmised that the specter of such a large fine probably led BP to settle rather than leave the question in Barbier’s hands.

“There’s no way around it: He has been unsympathetic to many, many of their legal requests and their factual arguments, and to think that would change when there’s billions of dollars at stake was probably a risk they weren’t willing to take,” said David Logan, a law professor at Roger Williams University in Rhode Island.

Edward Sherman, a Tulane University law professor who specializes in complex litigation, believes Barbier would have hit BP with a higher civil penalty than what the company agreed to pay in the deal. But he said any payout ordered by the court was likely to get tangled in years of future appeals, whereas this settlement should begin paying dividends soon.

“Obviously, the government felt that it was useful to end it now,” Sherman said.

Moving ahead with a settlement removes BP’s largest remaining area of legal exposure, an uncertainty that has plagued the company for years, and provides clarity on how much it ultimately will pay for its role in the worst environmental disaster in U.S. history.

The deal brings BP’s total price tag for the spill above $50 billion, including $14 billion that the oil giant spent on response and cleanup.

In 2012, the company agreed to plead guilty to 11 counts of felony manslaughter, obstruction of Congress and a series of environmental crimes, and to pay a $4 billion fine to settle a criminal case brought by the federal government.

It also has paid more than $5.2 billion so far from a 2012 class-action settlement reached with hundreds of thousands of private claims brought by Gulf Coast residents and businesses, and it also has made a multibillion-dollar settlement with the seafood industry.

BP’s drilling partners in the Macondo well, meanwhile, already have reached deals to resolve claims against them. Halliburton, which was BP’s cement contractor on the well, agreed to pay $1.1 billion to settle most claims for damages stemming from its role in the spill. It also pleaded guilty to a misdemeanor charge of destroying evidence in connection with the spill, and it agreed to pay a maximum $200,000 fine, serve five years of probation and donate $55 million to the National Fish and Wildlife Foundation.

Rig owner Transocean agreed in 2013 to pay $1.4 billion in civil and criminal fines and penalties, mostly to resolve federal Clean Water Act claims.

While some critics felt the deal was too easy on BP, others saw the earlier Exxon Valdez litigation as a cautionary tale of what can happen when a settlement isn’t reached.

The Valdez in 1989 dumped 11 million gallons of oil along more than 1,200 miles of Alaskan shoreline, and Exxon Mobil Corp. was initially ordered by a jury in 1996 to pay litigants $5 billion. But the figure was later cut to about $508 million on appeal.

“We do believe this is enough money. We wouldn’t be here if we didn’t,” Kyle Graham, executive director of the state Coastal Protection and Restoration Authority, said of Thursday’s settlement.

BP had argued in recent court filings that Gulf ecosystems have returned to normal and, in some cases, are healthier than ever. But many scientists contend it will take more time, perhaps decades, to grasp the spill’s full impact.

The $5 billion that Louisiana will receive for damage to natural resources results from five years of work by federal and state trustees to assess and put a value on the damage the spill caused.

The process involved scores of scientists conducting hundreds of studies designed to measure the spill’s toll on organisms and habitats, from marine mammals and sea turtles to mud flats and coral reefs.

“We established the science to ensure that we had a case,” said U.S. Rep. Garret Graves, R-Baton Rouge, Graham’s predecessor at thecoastal agency.

In 2011, BP agreed to a $1 billion down payment for all the Gulf Coast states. Louisiana’s share of that, $371 million, has been used for restoration work on various barrier islands, including Breton Island, Shell Island West, Chenier Ronquille and Whiskey Island.

The next step in the Natural Resources Damage Assessment process is finalizing the assessment and a plan for restoration, perhaps by early next year.