The saga of what some have called the worst environmental disaster in U.S. history passed a milestone on Thursday. BP, the company in charge of the Deepwater Horizon oil rig that exploded a mile above the Gulf of Mexico seafloor five years ago, announced that it has reached a comprehensive agreement with the federal government, as well as the states and the municipalities that were affected by the 3 million barrels of oil that gushed into the water.

The amount of BP money that will flow into Gulf Coast restoration over the next two decades is prodigious. Both BP and the government deserve credit for heading off a nasty and prolonged legal battle. What we still don’t know — and may not know for a very long time — is the extent of the damage the spill caused.

The multinational oil firm will pay an additional $18.7 billion over the next 18 years to settle various environmental and economic claims stemming from the accident. A rough estimate of BP’s total bill is now available: over $50 billion, according to Bloomberg Business, which is more than the company previously set aside to cover the costs of the accident. Under a law passed after the spill, most of the new money will go to the gulf. Louisiana Gov. Bobby Jindal, a Republican whose state stands to reap nearly $7 billion, promised on Thursday to fund a program to stop coastal erosion.

President Barack Obama determined in 2010 to demand accountability from BP without bankrupting the company. The latter goal served two purposes: maintaining BP’s capability to pay claims and maintaining the United States’ attractiveness to foreign investors, making clear that disasters such as the Deepwater Horizon spill would not be used as pretext to suck them dry. The upside for BP in Thursday’s settlement is that the company has essentially agreed to a payment plan, spreading its financial commitment into predictable and manageable chunks.

Though BP’s legal battles are nearly over, the effort to assess and restore the gulf is not. The company claims that the gulf’s ecosystems have been remarkably resilient, and there is truth to this. The region is not in the dire state that anyone watching oil spew into the water five years ago might have anticipated. But environmental groups and the government say it’s too early to tell the full effects. The Natural Resource Damage Assessment Trustees, who are charged with estimating how much harm occurred, warned this year that it’s “inappropriate as well as premature” to make any firm conclusions. But, they added, “From decades of experience with oil spills, we know that the environmental effects of this spill are likely to last for generations.”

From here, the challenge will be ensuring that federal, state and local authorities spend their money well, concentrating on the most pressing environmental problems facing the gulf.