BP PLC agreed to pay $18.7 billion to settle all federal and state claims arising from the 2010 Deepwater Horizon oil spill, including the biggest pollution penalty in U.S. history.

If approved by a federal judge, Thursday’s deal would conclude a monumental legal showdown over the Deepwater Horizon disaster, which killed 11 crew members aboard the drilling rig and caused the largest oil spill in U.S. waters.

The...