Originally part of the DreamWorks group created in the 1990s by Steven Spielberg, David Geffen and former top Disney executive Jeffrey Katzenberg, the studio was spun off as a separate company in 2004.
"DreamWorks will help us grow our film, television, theme parks and consumer products businesses for years to come," said Steve Burke, chief executive of Comcast unit NBCUniversal.
Under the deal, the animation studio will become part of NBCU's Universal Filmed Entertainment Group, which includes Universal Pictures.
Upon completion, the studio's chief executive Katzenberg will become chairman of DreamWorks New Media, which will include some NBCU television operations.
The new role for Katzenberg, which includes acting as consultant to NBC Universal, appeared to confirm reports he was giving up the reins at the studio he built.
"Having spent the past two decades working together with our team to build DreamWorks Animation into one of the world's most beloved brands, I am proud to say that NBCUniversal is the perfect home for our company; a home that will embrace the legacy of our storytelling and grow our businesses to their fullest potential," said Katzenberg.
"As for my role, I am incredibly excited to continue exploring the potential of AwesomenessTV, NOVA and other new media opportunities, and can't wait to get started," he said.
Burke said that Chris Meledandri, who heads Comcast's Illumination Entertainment unit, would "help guide the growth of the DreamWorks Animation business in the future."
The deal represents consolidation in a sector which is being challenged by the emergence of new Internet-based video services such as Netflix and Amazon, which are boosting their original programming.
It aims to strengthen NBCU programming for family and children in film, television and on-demand video potentially challenging the Walt Disney Co., which owns the Pixar animation studio.
Conquering the family space
In addition to hit movie series "Shrek," "Kung Fu Panda," "Madagascar" and "How to Train Your Dragon," Comcast will acquire a string of popular franchises such as "Shark Tale" and "Monsters vs Aliens."
The animation studio has released 32 feature films that together have pulled in more than $13 billion in global box office receipts.
Comcast has agreed to pay $41 a share in the deal, which has been approved by the boards of both companies and is expected to close later this year, subject to regulatory approvals.
As an independent studio, DreamWorks Animation has become an attractive target, "particularly for traditional media conglomerates that may increasingly look to diversify away from traditional TV networks," said Ryan Fiftal, a Morgan Stanley analyst, in a note to clients this week.
DreamWorks' "premium content and intellectual property is becoming increasingly scarce as new online video distributors compete aggressively for content that can stand out."
But Richard Greenfield at BTIG Research said the deal was overvalued and shows "a lack of financial discipline that should concern investors" of Comcast.
Greenfield wrote in a blog post that DreamWorks' "core movie business continues to struggle" and that "the quality of the television content has not been compelling to-date."
He argued that the studio has produced "very few iconic movies, beyond Shrek, Madagascar, Kung Fu Panda and How to Train Your Dragon."
Comcast, which is the largest US cable TV operator, acquired a majority of NBC Universal in 2009 and in 2013 boosted its stake to 100 percent.
That gave Comcast the large NBC television network as well as Universal Studios in Hollywood and its theme parks.
DreamWorks shares surged 24 percent to $39.95 on the news while Comcast added 0.64 percent to $61.70
Earlier this week, Comcast reported a first quarter net profit of $2.1 billion on $18.8 billion in revenues. Its 2015 profit was $8.2 billion on $74.5 billion in revenues.