If the DOJ-Bank of America settlement finalized, the deal would be the largest penalty ever paid by a single company, topping the $13 billion settlement that JPMorgan Chase reached with the department last year over similar charges. (Matt Rourke/AP)

Bank of America, the nation’s second-largest bank, is close to reaching an agreement with the Justice Department to pay a whopping $16 billion to resolve allegations that it knowingly sold faulty mortgage securities that contributed to the financial crisis, people familiar with the talks said Wednesday.

If finalized, the deal would be the largest penalty ever paid by a single company, topping the $13 billion settlement that JPMorgan Chase reached with the department last year over similar charges. The agreement would send Bank of America’s legal tab from the 2008 crisis soaring to $66 billion, while securing another win for a Justice Department that has been criticized for its effort to hold Wall Street accountable for its misdeeds.

One person familiar with the talks said the tab in this case could reach $17 billion. So far, the bank has agreed to pay about $9 billion in cash to Justice, states and other government offices, with the remainder of the money going to help struggling homeowners reduce their mortgage payments, said people familiar with the deal, who asked not to named because the talks are ongoing.

Negotiations stalled two months ago after the Justice Department and Bank of America could not agree on the structure of the deal. The bank offered to pay more than $12 billion, with most of the money going toward consumer relief, but federal prosecutors demanded a stiffer penalty.

Brian Moynihan, Bank of America’s chief executive, sought a meeting in June with Attorney General Eric J. Holder Jr., who declined the offer because the sides were too far apart, the people said. Talks cooled as Justice turned its full attention to wrapping up a $7 billion settlement with Citigroup over its role in the housing meltdown that sparked the crisis.

After that deal wrapped, attorneys for Bank of America resumed meetings with federal prosecutors but came no closer to a deal. Last Wednesday, Moynihan arranged for a call with Holder, who said the New Jersey U.S. Attorney Paul J. Fishman was prepared to file a lawsuit if the bank refused to raise its offer. By the end of the call, Moynihan conceded.

That same day, Bank of America had suffered a defeat when a federal judge ordered the bank to pay $1.27 billion in damages over thousands of defective mortgages sold by its Countrywide Financial unit. The award surpassed the $848.2 million sought by the Justice Department.

The ruling by U.S. District Judge Jed Rakoff in Manhattan came nine months after jurors found Bank of America and former Countrywide executive Rebecca Mairone liable for defrauding Fannie Mae and Freddie Mac, the government-controlled mortgage-finance twins.

Prosecutors alleged that Countrywide stripped safeguards designed to catch mortgage fraud from loans as part of a program known as “Hustle” and then peddled the mortgages to Fannie and Freddie. According to the complaint, the mortgage-finance companies were on the hook for more than $1 billion in losses once the housing market crashed.

Bank of America’s legal woes are largely tied to its $2.5 billion purchase of Countrywide Financial in 2008, once one of the nation’s largest home lenders, and its $50 billion acquisition of Merrill Lynch in 2009.

Indeed, the majority of the mortgage securities at the heart of the Justice investigation are the product of Countrywide and Merrill Lynch.

Bank of America packaged and sold $965 million worth of mortgage securities under investigation from 2004 to 2008, according to estimates from Sanford C. Bernstein analyst John McDonald. Nearly 96 percent of those securities came from Countrywide and Merrill.

Analysts have questioned whether the bank should be held fully liable for those securities, yet the argument has fallen on deaf ears.

The tentative deal with Justice could still fall apart, the people said. Both sides are still trying to flesh out the terms of the deal, including how the consumer portion will be doled out and what misdeeds Bank of America will acknowledge.

Spokesmen for Bank of America and the Justice Department declined to comment.