Ally Financial Inc agreed to pay $2.1 billion to Residential Capital LLC to settle claims that it stripped the bankrupt mortgage subsidiary of choice assets.

The deal will allow Ally to put behind it problems tied to mortgage lending so it can focus on its U.S. auto financing business and its online bank.

The settlement also paves the way for ResCap to repay its creditors.

Under the deal, detailed in a court filing on Thursday, Ally will pay $1.95 billion in cash and expects $150 million more to come from its insurers.

The deal is Ally's second attempt to reach a settlement, which has been complicated by residential mortgage-backed securities, or RMBS, issued by ResCap before its bankruptcy in May 2012.

The original settlement, filed last year, met with scorn from creditors who were not party to it, and the matter had been headed for trial.

Creditors who objected to the original deal included ResCap's unsecured creditors, bond insurers such as MBIA Corp and Assured Guaranty Corp , and others. They said the deal was controlled by Ally, which would have been shielded from claims in exchange for a contribution of $750 million to ResCap's creditors.

The U.S. government rescued Ally, formerly known as General Motors Acceptance Corp , in the wake of the 2008 financial crisis with a $17 billion bailout.

Ally has raised billions of dollars by selling its international business and wants to use that money to repay the government, which still owns three-quarters of the company following the bailout.

Under Thursday's agreement, MBIA will have a non-subordinated claim of $719 million against ResCap, and two claims of $1.45 billion each against two other bankrupt ResCap entities, GMACM and RFC.

Shares of MBIA rose 1.5 percent in morning trading; the broader stock market was lower.

The original settlement gave RMBS investors an $8.7 billion claim against ResCap. Creditors who objected said the figure was far too high and would eat into their own potential recoveries. Thursday's settlement trimmed those claims to $7.3 billion against two ResCap entities.

Ally said in a statement it expects to record a charge of $1.55 billion in the current quarter related to the settlement.

The agreement requires court approval. It has the support of major creditors like MBIA and the hedge fund Paulson & Co, but it remains to be seen whether other creditors will go along.

A time frame on the approval process was unclear Thursday morning.

A court-appointed examiner, former bankruptcy judge Arthur Gonzalez, investigated ResCap creditors' claims that Ally stripped ResCap of valuable assets before its bankruptcy.

Gonzalez's report was sealed from the public on the condition that the parties resolve their disputes.

On Wednesday, Warren Buffett's Berkshire Hathaway Inc asked Judge Martin Glenn to unseal that report so creditors could determine the fairness of the settlement.

(Reporting By Tom Hals in Wilmington, Delaware; Editing by Gerald E. McCormick and John Wallace)