Bank of America has agreed to pay about $16.6 billion to end federal and state investigations into the sale of toxic mortgage securities during the subprime housing boom, the largest settlement by a single company in U.S. history, according to people familiar with the negotiations.