Goldman Sachs finally rid itself of its troubled mortgage-servicing unit on Thursday, but only after reaching agreements with the Federal Reserve and New York’s top banking regulator over wrongful foreclosures.

The bank completed the sale of its Litton Loan Servicing subsidiary to Ocwen Loan Servicing after winning the approval of New York financial services superintendent Benjamin M. Lawsky. He had insisted that all three firms sign a deal to compensate borrowers who had faced improper foreclosures and to put an end to “robosigned” documents and other questionable practices.

Separately, the Federal Reserve announced sanctions against Goldman aimed at rectifying “a pattern of misconduct and negligence” at Litton, the agency said in a statement. The action requires Goldman to hire an independent consultant to examine numerous foreclosures initiated by Litton in search of borrowers who “suffered financial injury” as a result of mishandled foreclosures. Goldman also agreed to pay any future monetary penalties that the Fed levies against Litton for its conduct.

The bank declined comment Thursday.

Under the New York agreement, Goldman and the other firms vowed to cease robosigning documents and to withdraw any inaccurate or falsely signed affidavits. The practices had become commonplace within the industry and prompted nationwide outrage when they came to light last fall. Servicers also must provide a “single point of contact” to prevent the predicament that borrowers often encounter of facing a foreclosure even while trying to obtain a loan modification.

In cases where borrowers have been wrongfully foreclosed upon, the servicers agreed to remedy the situation, either by restoring the homeowner’s equity in property or providing compensation if it has been sold.

In addition, Goldman agreed to forgive a portion of the balance on some delinquent home loans in New York that are serviced by Litton.

“This agreement provides important consumer protections for homeowners who have found themselves in dire straits due to the financial crisis,” Lawsky said in a statement, adding that the deal “sets a new, higher standard for the residential mortgage servicing industry, whose troubling foreclosure and servicing practices we have been investigating along with other regulators across the country.”

The deal with Lawsky was a condition for the Litton acquisition and does not preclude any future investigations or claims. The shape of the agreement underscores fundamental changes that other state and federal officials have been been pushing for in the loan servicing industry, as well as changes that servicers largely seem willing to accept.

The actions involving Goldman come as a coalition of state attorneys general and federal officials try to finalize a settlement with the country’s five largest mortgage servicers — Bank of America, Wells Fargo, Ally Financial, J.P. Morgan and Citigroup — over a similar set of problems.

That effort would compel those firms to drastically alter the way they service loans and interact with struggling borrowers, and would impose about $20 billion in penalties that would be used to fund foreclosure-prevention efforts.

Those negotiations remain a work in progress. New York Attorney General Eric Schneiderman and others have raised concerns that banks could be given too broad a legal release from future mortgage-related claims in exchange for a settlement.

Litton’s value has fallen considerably since Goldman purchased the company in late 2007. The bank set about shedding the firm earlier this year and found a buyer in Ocwen, which in June agreed to purchase Litton for $264 million.

Because Goldman will no longer be in the mortgage-servicing business, the changes to foreclosure practices mandated by Thursday’s agreement are aimed primarily at Ocwen and Litton, which together will comprise the country’s 12th largest mortgage servicer.