Updated from 3:15 p.m. EST

In a last-minute deal, Liberty Media ( LINTA) saved Sirius XM ( SIRI) from bankruptcy with a $530 million loan infusion giving John Malone's company a 40% stake in the satellite radio shop.

As reported, Sirius CEO Mel Karmazin was scrambling Monday to close the deal with Liberty Media and not only save Sirius XM from bankruptcy, but also fend off a takeover bid by Dish Network ( DISH) operator Charles Ergen, who has sought to oust Karmazin.

The deal -- news of which sent shares soaring more than 50% -- has two phases. The first installment is an immediate $280 million secured loan to pay off a $171.6 million obligation that was due Tuesday. The remaining money will be used to keep Sirius operating and to cover transaction costs. The second stage of the Liberty investment calls for another $150 million loan to XM Satellite Radio, with an agreement to buy $100 million in XM loans outstanding.

Given the tight credit market and the unwanted takeover option from Dish, Sirius agreed to pay a 15% interest rate on the Liberty Media loans. In exchange for the loan, Sirius will issue 12.5 million shares of preferred stock that will convert to a 40% stake in the company's common stock.

Malone and Liberty Media CEO Greg Maffei will take two seats on the Sirius board of directors.

"This agreement enables Sirius XM to continue to develop the opportunities first outlined in the merger of Sirius and XM," Karmazin said in a press release. "By strengthening our capital structure and enhancing our financial flexibility, this investment allows us to continue providing the great content and innovative programming."

Saddled with heavy programming and equipment costs, Sirius XM hit significant challenges in trying to refinance its debts as the recession cut into auto sales and consumers spent less on services and electronics.

The satellite radio network apparently holds some promise for the satellite TV players who may want to use the infrastructure to deliver more content like Internet or mobile TV.

The Liberty Media group controls DirecTV ( DTV), the satellite TV giant that competes with Ergen's EchoStar ( SATS) and Dish Network.

Sirius shares surged 6 cents, or 52.5%, to 16 cents.

More from Technology

Tuesday Turnaround in Politics: Is a Trade War on the Horizon?

Tuesday Turnaround in Politics: Is a Trade War on the Horizon?

FANG Stocks Get Swept Up in Broader Market Selloff

FANG Stocks Get Swept Up in Broader Market Selloff

Snap Shares Plunge After Cowen Cuts Price Target

Snap Shares Plunge After Cowen Cuts Price Target

Netflix Shares Hit All-Time High as Market Flounders

Netflix Shares Hit All-Time High as Market Flounders

18 Auto Stocks Trump Just Ran Over With His China Tariff Attack

18 Auto Stocks Trump Just Ran Over With His China Tariff Attack