Comcast Corp. will buy Time Warner Cable Inc. for about $45.2 billion in a deal that combines the nation's top two cable TV companies and would create a dominant force in both creating and delivering entertainment to U.S. homes.

The all-stock deal was approved by the boards of both companies. It is expected to close by the end of the year, pending shareholder and regulatory approvals.

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

Time Warner Cable shareholders will receive 2.875 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.

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, which also owns NBCUniversal, 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, 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. Comcast operates mainly in the northeast including its home base of Philadelphia and places such as Boston, Washington and Chicago. Time Warner Cable has strongholds around its headquarters in New York as well as Los Angeles, Dallas and Milwaukee.

"In fact, we do not operate in any of the same zip codes," Comcast chief Brian Roberts told analysts in a conference call about the deal.

In many of those areas, the combined Comcast/Time Warner Cable will face competition from rivals AT&T and Verizon, which 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.

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.

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.

Craig Aaron, president and CEO of Free Press, a national advocacy group focused on media and technology said the deal would mean higher rates for consumers and fewer choices in content.

"The idea that we would allow the nation's already largest cable company and internet service provider to merge with the second biggest cable company is going to give way too much power to Comcast over what we watch, see, hear, and download every day," Aaron told KPCC.

"People in Los Angeles should be very worried because if you didn't like the current cable guy, you're really not going to like the cable guy on steroids," Aaron said.

Time Warner Cable already struggles with an image problem in the Los Angeles market.

The company has been involved in some disputes -- which in the end denied some Angelenos programming for a spell. In 2012, the cable company got tough in dealing with competitors like DirecTV who wanted to carry the new Lakers channel. And then last year, Time Warner Cable's dispute with CBS resulted in a black-out of CBS-owned channels for more than a month.

"You've seen Time Warner exercising its local monopoly power here," said John Simpson of Consumer Watchdog at news conference in its Santa Monica office.

"Los Angeles and several other Time Warner cities are examples of what the rest of the country would be likely to expect if this deal goes through," Simpson said.

But analyst Robin Flynn of SNL Kagan said while Time Warner Cable has become known for its public spats, Comcast has tried to avoid them.

"So I think going forward, you could probably see Comcast continue that same kind of approach to doing programming deals where it really prefers stability, long-term deals, and a more private form of negotiation," Flynn said.

In its "First Look" at the proposed merger, Media and Telecommunications research firm Moffett Nathanson said regulators in Washington, DC should expect to hear opposition from a range of interests:

After the proposed divestiture of 3 [million] subscribers, the new Comcast will have 30% of all Pay TV customers. This is a full 50% larger than the next largest provider, DirecTV, and more than twice as large as the number three player, Dish Network. Independent programmers, in particular, will complain that Comcast will now be simply too powerful; a threat from the new Comcast to drop carriage would amount to threat of a death sentence (or so they will claim). Expect a cacophony of protest.

Shares of Time Warner Cable closed on Thursday at $144.81, up 7 percent. Comcast shares fell 4 percent to $52.97.