Dish and Viacom have reached a deal hours before 13 million people were set to lose MTV, Comedy Central, and more

James Franco during a Comedy Central roast. Comedy Central is a Viacom property. Kevin Winters / Getty Images Television provider Dish Networks and content creator Viacom have reached a deal that will prevent the latter's networks from being blacked out.

The deal was reached hours before Viacom's channels, which include MTV, Comedy Central and Nickelodeon, would have disappeared for the more than 13 million Dish subscribers.

The deal also will include Viacom's channels being offered on Dish's Sling TV, a smaller offering of fewer channels at a lower price.

"We appreciate Viacom's willingness to continue with us on our journey as we work to deliver the best, most innovative television services available," said Charlie Ergen, DISH chairman and CEO in a release announcing the move. "This creative, bold and consumer-friendly approach extends a nearly 20-year-old relationship."

Viacom was equally pleased with the move.

"DISH has historically been and remains an important partner for Viacom, and as part of our commitment to entertain audiences wherever they are, we are pleased to offer select Viacom networks as part of DISH's Sling TV product," CEO Philippe Dauman said in the release.

"Today's renewal, together with several additional affiliate agreements announced over the past year, will enable Viacom to drive growth and deliver better, more engaging viewer experiences for years to come."

The agreement came after days of back and forth which included Viacom launching a website telling its customers to call Dish and ask them to agree to terms. Additionally, Dish claimed that Viacom was asking far too much for its channels even when ratings were declining.

Despite the harsh tone, the two sides were evidently able to reach an agreement. Financial terms, including the size of carrier fees for Viacom, were not readily available.

In response to the news, Viacom's stock surged nearly 9%, paring losses from earlier in the week. Dish stock was little changed, up just under 1%.