LOS ANGELES (AP) — Comcast Corp. has agreed to buy Time Warner Cable Inc. for $45.2 billion in stock, or $158.82 per share, two people familiar with the matter said late Wednesday.

The deal will combine the nation's top two cable TV companies and make Comcast, which also owns NBCUniversal, a dominant force in both creating and delivering entertainment to U.S. homes.

The deal was approved by the boards of both companies and, pending regulatory approval, is expected to close by the end of the year, the people said.

The people spoke on condition of anonymity because the deal had not been announced formally. An announcement is set for Thursday morning, they said.

The price is about 17 percent above Time Warner Cable shares' Wednesday closing price of $135.31 and trumps a proposal by Charter Communications Inc. to buy Time Warner for about $132.50 per share, or $38 billion in cash and stock.

Time Warner Cable shareholders will receive 2.57 Comcast shares for every Time Warner Cable share they own. Once the deal is final, they will end up owning about 23 percent of the combined company, one of the people said.

Charter had pursued Time Warner Cable for months but Time Warner Cable CEO Rob Marcus had consistently rejected what he called a lowball offer, saying he'd cut a deal for $160 per share in cash and stock.

For a time, Comcast stayed in the background, waiting to purchase any chunk of subscribers that a combined Charter-Time Warner Cable would sell off. Charter had planned to finance its bid with $25 billion in new debt. As part of a plan to pay off the debt quickly, the company considered selling off some of its territories after a deal had closed. Time Warner Cable's Marcus had also balked at the huge debt burden the Charter takeover represented.

Instead, Comcast now plans to divest 3 million pay TV subscribers after the deal closes. With 22 million of its own pay TV customers and Time Warner Cable's 11.2 million, the combined entity will end up with about 30 million subscribers when the deal is complete, a level believed not to trigger the concern of antitrust authorities. A formal cap was dissolved years ago by regulators, but divesting subscribers could help the deal get approved more quickly.

Comcast is taking the position that because Comcast and Time Warner Cable don't serve overlapping markets, their combination won't reduce competition for consumers, especially in the face of rivals AT&T and Verizon, which compete with the cable operators to provide both pay TV services and Internet hookups. Both AT&T and Verizon are growing quickly. They ended 2013 with 5.5 million and 5.3 million pay TV subscribers, respectively.

Comcast and Time Warner Cable are expected to save $1.5 billion in annual costs over three years, with half of that realized in the first year, one of the people said.

Comcast also plans to add an additional $10 billion in share buybacks at the close of the deal, on top of a recent plan to boost its share buyback authority to $7.5 billion from $1 billion, the person said.

Conceding that it had lost the takeover battle, Charter issued a statement Wednesday saying, "Charter has always maintained that our greatest opportunity to create value for shareholders is by executing our current business plan, and that we will continue to be disciplined in this and any other (merger and acquisition) activity we pursue."

Even before the deal had been formally announced, it was being denounced. Public Knowledge, a Washington-based consumer rights group, said in a statement Wednesday that regulators must stop the deal, because it would give Comcast "unprecedented gatekeeper power in several important markets."

"An enlarged Comcast would be the bully in the schoolyard," it said.