After months of lowball offers and heels dug in, it took only 24 hours for Bank of America to suddenly cave in to the government, agreeing to the largest single federal settlement in the history of corporate America.

The tentative deal ? which people briefed on the matter said would cost Bank of America more than $16 billion to settle investigations into its sale of toxic mortgage securities ? started to take shape last week after the justice department rejected yet another settlement offer from the bank. Then, a wild card entered the fray.

Judge Jed Rakoff, a longtime thorn in the side of Wall Street and Washington, issued an unexpected ruling in another Bank of America case that eroded what was left of the bank?s negotiating leverage. Rakoff, of Federal District Court in Manhattan, ordered the bank to pay nearly $1.3 billion for selling 17,600 loans, many of which were defective. The bank had previously lost that case, which involved its Countrywide Financial unit, at a jury trial.

The bank?s top lawyers and executives, who made the ill-fated decision to fight that case in Rakoff?s court rather than settle, appeared to recognise that another courtroom battle would not only be futile but extremely expensive, according to two of the people briefed on the matter. The remaining cases, which by contrast would involve billions of dollars in securities backed by home loans, could have cost the bank multiples more than Rakoff?s penalty, perhaps even more than a settlement with the justice department.

With the bank reeling from the judge?s decision, attorney general Eric Holder delivered the final blow. Holder, who had rebuffed earlier requests for a meeting with the bank?s CEO, decided to open the lines of communication. In a phone call July 30 with the bank?s CEO, Brian Moynihan, Holder delivered a simple demand: Raise your offer or be sued the very next day. Holder, the people briefed on the matter said, provided an 8 am Thursday deadline.

Around 7.50 am on July 31, one of the people said, a bank lawyer called to offer $9 billion in cash and more than $7 billion in so-called soft-dollar relief to consumers. That offer, which provided the crux of the tentative settlement, was within striking distance of the justice department?s initial demands. It also was far in excess of what JPMorgan and Citigroup paid to settle similar cases in recent months.

Bank of America?s decision to back down, despite its earlier bare-knuckle brawls with the government, showed the limitations of legal arguments it has clung to for years. The bank, seeking to placate shareholders, has long argued that it should not be harshly penalised for the misdeeds of Countrywide Financial and Merrill Lynch, the companies it bought in the financial crisis.

In the case of Merrill, the bank argued that federal regulators pressured it to go through with the buy. With Countrywide?s mortgages, it claimed that it did not assume legal liabilities stemming from many of the loans that it had made before its acquisition.

The deal would bring a measure of closure to the bank, which has already paid tens of billions of dollars to settle lawsuits by private investors and regulators over its mortgage operations. The deal, capping the bank?s largest remaining legal issue from the financial crisis, would in turn accelerate Bank of America?s effort to return to the business of being a bank.

The settlement, however, could still fall apart. The two sides continue to negotiate a statement of facts outlining the bank?s misconduct, the people briefed on the matter said. They are also discussing how to divide the so-called soft-dollar relief for consumers.