A federal bankruptcy judge on Thursday approved Edward S. Lampert’s plan to buy Sears, but the judge implored Mr. Lampert to make a fresh start.

Mr. Lampert, a billionaire hedge fund manager, could avoid becoming the “cartoon character” his critics have painted him as, Judge Robert Drain said — a cross between Jay Gould, the Gilded Age robber baron, and Barney Fife, the blustery gullible sheriff on the “Andy Griffith” show.

Rather, Judge Drain said, Mr. Lampert could “take action that would in fact be of great meaning” to the company’s constituents, particularly its workers.

The remarks capped an all-day hearing on the fate of Sears, which filed for bankruptcy in October.

At stake was whether Sears, a company founded shortly after the Civil War, would shut its doors or continue operating with less debt and a sound turnaround strategy.

But the hearing was also a referendum on Mr. Lampert, the company’s chief executive and largest shareholder who has controlled Sears since 2005.

Many of the company’s creditors accused Mr. Lampert and his hedge fund, ESL Investments, of running Sears into the ground, racking up losses and falling behind competitors, while spinning off the company’s most valuable assets in ways that enriched his hedge fund.

They questioned why Mr. Lampert, after years of failing to turn around the company, should be given the opportunity to acquire Sears out of bankruptcy. A committee of creditors wanted to liquidate the company and collect the proceeds, rather than take another risk on Mr. Lampert.

As the only bidder that planned to keep Sears operating, Mr. Lampert had positioned himself as a savior, preserving 45,000 jobs and honoring contracts with thousands of vendors.

But lawyers for the creditors committee warned that Mr. Lampert’s plan includes hundreds of millions of dollars of asset sales, which could result in substantial job cuts anyway.

In the end, Judge Drain determined that the sale of Sears to Mr. Lampert, for $5.2 billion, made sound business sense. He said the creditors failed to prove that they would recover more money by selling off the stores and other properties.

The deal is not yet complete. Sears and ESL are still working out the final details and lawyers for the companies said they were hoping to close on Friday. Sticking points remain, including which side would be responsible for $166 million owed to vendors.

The creditors committee nevertheless won an important concession in the case. It can still file lawsuits against Mr. Lampert for past deals that resulted in spinning off real estate and other valuable assets to companies that his hedge fund had stakes in. A lawyer for ESL said the claims were without merit.

David Wander, a lawyer at Davidoff Hutcher & Citron, who represents several Sears vendors in the bankruptcy, said the court imparted a clear warning to Mr. Lampert.

“The judge was warning that you claim to want to save tens of thousands of jobs, I hope that is what you do and not end up liquidating the company over the next few years,” Mr. Wander said.