CBS and Viacom have agreed to merge, ending years of on-and-off talks.

The new company will be called ViacomCBS, and Viacom's CEO, Bob Bakish, will be the CEO of the combined company. Joe Ianiello, who was serving as CBS CEO since last year, will be the chairman of CBS and will be in charge of CBS assets after the merger.

Existing CBS shareholders will own about 61% of the combined company, with Viacom shareholders owning the remaining 39%. Each Viacom shareholder will receive .59625 shares of CBS shares. CBS shares rose 1.5%. Viacom shares rose 1.77%.

The combination reunites the two media companies controlled by Sumner Redstone's National Amusements. Viacom spun off CBS in 2006. Redstone's daughter, Shari, is the vice chairman of the board at both CBS and Viacom and has long desired putting the companies back together to gain scale in a media environment where competitors including Disney, Comcast and AT&T have bulked up through a series of megadeals.

"I am really excited to see these two great companies come together so that they can realize the incredible power of their combined assets," Redstone said in the statement. "My father once said 'content is king,' and never has that been more true than today."

A merger will add movie studio Paramount Pictures, cable networks such as Comedy Central, MTV, Nickelodeon and BET, and other assets including the streaming service Pluto TV and South Park Studios to CBS, which owns the eponymous broadcast network, Showtime, and other assets. The added scale will help ViacomCBS compete with Netflix, Amazon and other legacy media companies on spending. ViacomCBS has spent more than $13 billion in the past 12 months, the companies said in a statement.

CBS and Viacom plan to "accelerate" their streaming strategies and expand globally, according to the statement. The companies have not said if they plan to offer a combined streaming product, such as Warner Media's HBO Max. CBS's CBS All Access and Showtime Anytime already have more than 8 million subscribers combined. Viacom offers niche streaming products such as the $7.99-per-month kids service Noggin.

The companies estimate $500 million in annualized run-rate synergies within 12 to 24 months.