A U.S. judge ruled on Thursday that auto parts maker Delphi Corp (DPHIQ.PK) can sell itself to a group of lenders, paving the way for the company to end its near four-year trip through bankruptcy court.

Earlier this week Delphi's board accepted a bid from its debtor-in-possession lenders, including several hedge funds, to take over much of its operations. In exchange, the lenders, which include Elliott Management Corp, Monarch Alternative Capital and Silver Point Capital LP, agreed to forgive nearly $3.5 billion of debtor-in-possession (DIP) loans.

General Motors, Delphi's former parent, would take over some of the company's U.S. plants, and has agreed to provide some further funding to Delphi.

Judge Robert Drain approved the sale during the second day of a hearing in U.S. bankruptcy court in Manhattan, saying he believed the auction process for the company was fair and
would bring a successful conclusion to a company that has been through a set of colossal and remarkable problems in its own case and with the industry.

The deal with its lenders marks the latest in a series of attempts to get Delphi out of bankruptcy. In April 2008, investors led by Appaloosa Management backed out of a plan that would have provided $2.55 billion of financing.

It also thwarts an effort made earlier this year by Platinum Equity Capital Partners, a Beverly Hills, California, private equity firm, to take over Delphi, in a deal with GM that had won the backing of the federal government's auto task force.

The emergence of Delphi from bankruptcy would help GM, which spun off the Troy, Michigan-based company in 1999 and remains one of its biggest customers.

If Delphi had been forced to liquidate, it would have deprived GM, which came out of its own Chapter 11 case earlier this month, of a key supplier which could have led the nation's largest automaker to halt vehicle production, at least for a time.

Under the deal, Delphi will emerge as three companies: New Delphi; a General Motors subsidiary which will contain its steering business; and a company called DPH Holding Co, which
will dispose of certain non-core Delphi businesses, according to the company's lead bankruptcy lawyer, Jack Butler of law firm Skadden Arps Slate Meagher & Flom.

Delphi hopes to close the sale by the end of the third quarter and is targeting Aug. 31 as a closing date, Butler said on Wednesday.

Last week, Delphi said it will terminate its salaried and hourly pension plans, sticking the government's Pension Benefit Guaranty Corp with a $6.2 billion liability. GM is expected to
cover some of the cost.

The case is In re Delphi Corp, U.S. Bankruptcy Court, Southern District of New York (Manhattan), No. 05-44481.

(Reporting by Emily Chasan and Jonathan Stempel, editing by Matthew Lewis)