The Magna deal was announced in the early hours of Saturday
Germany has agreed a deal with Magna International, a Canadian car parts maker, to take over Opel, part of the European wing of US carmaker GM.
Talks in Berlin continued into early Saturday before Germany's finance minister announced the rescue deal.
The German government is expected to provide an immediate loan facility of 1.5bn euros ($2.1bn, £1.3bn).
The Magna deal should protect Opel if GM files for bankruptcy protection in the US on Monday, as is expected.
The Canadian company has said it will put more than 500m euros ($700m; £435m) into Opel, which employs more than 25,000 people in Germany.
Significant numbers of workers are also spread around Spain, Belgium, Poland and the UK, where Opel cars are branded as Vauxhall for British customers.
Magna's bid was backed by Russia's state-run bank Sberbank and Russian magnate Oleg Deripaska's truck firm Gaz. The consortium hopes to see GM expand its reach into the Russian market.
German Finance Minister Peer Steinbrueck told journalists outside the chancellery shortly after 0200 local time on Saturday that a deal had been agreed.
MAGNA'S BID FOR GM EUROPE
Canadian-Austrian car parts group
Plans 2,500 job cuts in Germany
Pledges to inject between 500m and 700m euros into Opel
10% of the new company would be owned by Opel employees; GM would keep a 35% stake in the company
Bid in connection with Russia's state-run Sberbank and Oleg Deripaska's truck firm Gaz
"A solution has been found to keep Opel running," said Mr Steinbrueck, after six hours of talks between German politicians, US government officials and executives from General Motors and Magna.
Mr Steinbrueck said that although it was impossible to exclude all risk, the deal agreed would safeguard Opel's sites in Germany and preserve "the highest possible numbers of jobs" there.
Before the announcement of the deal, Magna said it planned to cut 2,500 jobs in Germany, about 10% of Opel's workforce in that country. Italy's Fiat, a former potential bidder, had said it would cut 10,000 jobs.
GM operations in Europe will now be placed under the care of a trustee to shield them from the parent company's filing for bankruptcy protection in the US.
The BBC's Steve Rosenberg, in Berlin, says the Germans wanted to ringfence Opel from the mother company and this has been achieved.
It is a key breakthrough, our correspondent adds, and quite surprising considering that a few hours before the situation had looked quite hopeless, with Fiat walking away from the bid and Magna appearing to get cold feet.
Details of the final deal with Magna have not yet been released, but the terms of the agreement are thought to involve GM keeping a 35% stake in the company, while 10% would be owned by Opel employees.
UK Business Secretary Lord Mandelson said Magna had given a "clear commitment" to continuing production of cars in the UK.
But, he said, it was likely that change lay ahead, as there was "excess capacity" in GM's operations in Europe.
On Friday, a court in Sweden granted Saab, GM's other European business, an extension to its protection from creditors.
The Swedish carmaker first sought protection in February. It now has until 20 August to line up a new owner and to restructure its business.
Saab is being sold off by GM separately.
In the US, General Motors executives on Friday successfully agreed a major cost-saving deal with workers in an effort to pave the way for a major restructuring of its US-based business.
Magna has received Berlin's approval to take over Opel from GM
Three-quarters of all United Auto Workers (UAW) union members voted to accept a freeze on pay and an end to bonuses - cutting labour costs by up to $2bn a year, the union said.
It also agreed to cut health benefits to retired employees.
Instead of the company funding health care costs for former workers, the union health trust will do so. The union will take an ownership stake in return for absolving GM of its responsibilities.
UAW also agreed not to strike until 2015 in a bid to shore up the company and save jobs.
Despite the concessions, 21,000 jobs are expected to be lost and several plants will be closed in the US.
"We've given a lifeline to GM until they can rebound," said Ron Gettelfinger, UAW president.
By 1 June, ownership of the US based business is expected to be shared between the US government (72.5%), the union's health trust (17.5%) and GM's former creditors.