The British oil company BP has agreed to pay $18.7 billion to five Gulf Coast states and the federal government in damages over the 2010 Deepwater Horizon oil spill.The tentative settlement brings to an end a trial that began more than two years ago, in one of the most complex and closely watched civil cases in American history, and it comes on top of more than $4 billion in criminal fines that BP had already agreed to pay.The company estimates that it will ultimately spend more than $40 billion in costs from the spill, including about $14 billion it spent in a three-month effort to contain the spill, which left much of the American public spellbound as images of the oil escaping the well hour after hour were aired on television.