The federal government and the Gulf Coast states have reached a tentative deal with the British oil company BP for it to pay about $18.7 billion, the largest environmental settlement in American history, to compensate for damages from the 2010 Deepwater Horizon oil spill, federal, state and company officials said Thursday.