(Reuters) - Viacom Inc and DirecTV Group said they reached an agreement to restore Viacom networks to the satellite TV provider's 20 million U.S. subscribers.

Viacom will restore all its channels, including Nickelodeon, Comedy Central, MTV and Spike, which became unavailable to DirecTV customers from July 10.

The two companies had been in talks over a new contract but could not agree on its terms before the July 10 deadline, leading to the blackout.

The previous contract was in place for the last seven years.

The companies did not disclose the financial terms of the new contract.

The new contract will let DirecTV customers see Viacom's programming on tablets, laptops, handhelds and other personal devices.

"The attention surrounding this unnecessary and ill-advised blackout by Viacom has accomplished one key thing: it serves notice to all media companies that bullying TV providers and their customers with blackouts won't get them a better deal," said Derek Chang, an executive vice-president of DirecTV.

The standoff was the latest between media companies and cable and satellite TV providers over the cost of content. These providers pay a fee to media companies that allows them to carry channels such as MTV.

Viacom shares closed at $46.65 on the Nasdaq on Thursday. DirecTV shares closed at $48.95 on the same exchange.

(Reporting by Supantha Mukherjee in Bangalore; Editing by Joyjeet Das)