Comcast Corp. said it agreed to buy Time Warner Cable for about $45.2 billion in stock, in a deal that would combine the nation's two biggest cable operators.

The boards of both companies have approved the transaction, which was announced Thursday morning.

With the proposed deal, Comcast almost certainly ends an eight-month takeover battle...