The company agreed to pay nearly $18 billion and pledged to impose new safety controls on Facebook and Instagram.