Updated from 3:15 p.m. ESTIn 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."