Time Warner Inc. (TWX) and Comcast Corp. (CMCSA) have reached an agreement to buy the assets of the bankrupt cable company Adelphia Communications Corp. (search) in a deal valued at $17.6 billion in cash and stock.

The deal beat out a last-minute bid by Cablevision Systems Corp. , a New York-area cable TV company, and still faces several steps before closing, including approval by regulators and bankruptcy court.

Time Warner and Comcast will pay $12.7 billion in cash and 16 percent of the stock in Time Warner's cable subsidiary, Time Warner Cable Inc., which will become a publicly traded company at the time the deal closes. A source close to the deal but speaking on condition of anonymity valued the stock part of the payment at $4.9 billion. Time Warner and Comcast will also swap cable customers.

As part of the multipart deal, Comcast will give back its 21 percent interest in Time Warner Cable and pay about $1.5 billion in cash. It will wind up with an additional 1.8 million cable subscribers as a result of the deal. Time Warner will gain 3.5 million subscribers.

Investors applauded the news that a final deal had been reached after several months of discussions. Time Warner's shares rose 28 cents or 1.7 percent to $17.21 on the New York Stock Exchange (search), while Comcast rose 63 cents or 2 percent to $32.13, also on the NYSE.

For Time Warner, the transaction marks the first major acquisition since the disastrous merger with AOL in 2000. Since then, the company has disposed of several businesses including its music company, bolstering its balance sheet in the process.

After the deal closes, Comcast will maintain its lead as the largest cable TV company in the country, with 23.3 million customers, and Time Warner will remain No. 2 with 14.4 million subscribers.

The deal expands the reach of both Time Warner and Comcast, and allows them to arrange their subscribers more efficiently in geographic clusters, making it easier to save costs and make upgrades to cable systems.

For Time Warner, floating shares in its cable company also allows investors to assign a separate value to the company's burgeoning cable business, which has been growing strongly due to new revenues from premium services like high-speed Internet, digital cable service and voice telephony.

Having a separately traded stock in a cable company will also provide Time Warner with a "currency" with which to make future acquisitions in the cable business, something that Time Warner CEO Dick Parsons has said he wants to do.

"This structure gives us an awful amount of flexibility" for growing the cable business and also regulating Time Warner's exposure to it, Parsons told analysts on a conference call Thursday.

Parsons also said he expected to keep the dual-stock structure in place for the long term, meaning the company didn't intend to sell off the cable business to Comcast or another company.

The companies said they expect the deal to close in the next 9 to 12 months.

Adelphia, which is based in Colorado, has been operating under bankruptcy protection since 2002 after collapsing in an accounting fraud and corporate looting scandal. Company founder John W. Rigas and his son Timothy were convicted of conspiracy, bank fraud and securities fraud.