Comcast Corp (CMCSA) said on Thursday it would buy Time Warner Cable Inc (TWC) for $45.2 billion in an all-stock deal that combines the two largest U.S. cable operators.

The friendly takeover comes as a surprise after months of public pursuit of Time Warner Cable by smaller rival Charter Communications Inc, and immediately raised questions as to whether it would pass the scrutiny of anti-trust regulators.

Comcast will pay $158.82 per share, which is roughly what Time Warner Cable demanded from Charter.

The combined company would divest 3 million subscribers, about a quarter of Time Warner's 12 million customers. Together with Comcast's 22 million video subscribers, the roughly 30 million total would represent just under 30% of the U.S. pay television video market.

The new cable giant would tower over its closest video competitor, DirecTV, which has about 20 million video customers.

If successful, the deal will be the second time in little more than a year that Comcast has helped reshape the U.S. media landscape after its $17 billion acquisition of NBC Universal was completed in 2013.

The proposed combination, which would give roughly 23% of the merged company to Time Warner Cable shareholders, is subject to approval from the U.S. Department of Justice and the Federal Communications Commission. The two companies expect to close the deal, which has no break-up fee, by the end of the year.

The new partners are concentrated in different cities. Comcast would fill in its New Jersey and Connecticut portfolio with Time Warner Cable's New York City customers, for instance, and add major markets such as Los Angeles and Dallas.

"Comcast and Time Warner Cable don't compete and Comcast can easily divest a few million subscribers," said BTIG analyst Rich Greenfield.

While the attempt to merge the two largest U.S. cable operators would face close scrutiny, a divestiture of subscribers should help its case with regulators, he added.

It was not yet clear which markets Comcast would sell.

The companies expect to create $1.5 billion in operating savings, with 50% of those savings expected in the first year.

Representatives for the U.S. Federal Communications Commission and the Department of Justice could not be reached for comment.

The proposed deal will be accretive to Comcast, which plans to expand its stock buyback program to $10 billion at the close of the transaction.

Smaller cable operator Charter went hostile this week by nominating a slate of directors to replace the entire board of Time Warner Cable. Charter offered $132.50 per share in a cash and stock deal last month that was rejected as too low.

"Charter has always maintained that our greatest opportunity to create value for our shareholders is by executing our current business plan, and that we will continue to be disciplined in this and any other M&A activity we pursue," Charter said after news of the Comcast deal broke Wednesday night.

A YEAR IN THE MAKING

Talks between Comcast and Time Warner Cable started about a year ago, but negotiations gathered pace in recent weeks, people familiar with the matter said. Time Warner Cable had told Comcast it considered Comcast to be its preferred buyer once Charter had approached them, the sources said.

Officials at Charter did not respond to a request for comment.

Comcast had also been in talks with Charter about the possibility of carving up Time Warner Cable markets, but opted not to participate in a hostile situation, the people said.

Comcast is interested in advertising synergies it would gain by owning the New York City market as well as the opportunity to expand its business services unit, its fastest growing cable division, to a larger footprint.

"For Comcast, adding New York and Los Angeles has advertising potential, along with Time Warner Cable's sports assets, which provides an acquisition target that is simply too compelling to ignore, especially with an (under-leveraged) balance sheet," Greenfield said.

Time Warner Cable owns two regional sports networks in Los Angeles, where it has spent billions on local TV rights for LA Lakers basketball and LA Dodgers baseball.

The deal would be a coup for Time Warner Cable Chief Executive Rob Marcus, who just ascended to the top job on Jan 1. Filings show that the former mergers and acquisitions attorney is set to pocket $50 million if Time Warner Cable is sold and he is replaced while he is CEO.

J.P. Morgan (JPM), Paul J. Taubman, and Barclays Plc (BCS) acted as financial advisors to Comcast. Morgan Stanley (MS), Allen & Company, Citigroup (C) and Centerview Partners are financial advisors to Time Warner Cable on the deal.

Follow Matthew Rocco on Twitter @MatthewRocco