Rocky and Bullwinkle may have received shabby treatment when they were turned into a feature some fifteen years ago (a disgrace that producer-star Robert De Niro still hasn’t lived down), but the time-travelling dog and his adopted son who shared their series have made the transition from the tube to the big screen with a degree of wit that might have made their creator, the late Jay Ward, smile in appreciation. “Mr. Peabody & Sherman” has its less inspired stretches, but for the most part it’s charming and funny, a nostalgia trip that should also appeal to newcomers.

Of course the film devised by writer Craig Wright and director Rob Minkoff can’t simply duplicate the approach of the ultra-short pieces Ward fashioned. It does retain the basic set-up and mimic their outlandish sense of humor and penchant for terrible puns, but necessarily has to fashion a narrative that can sustain a full ninety minutes. This version, therefore, is basically set in a contemporary New York that nonetheless looks like something vaguely out of the sixties, and includes both a montage showing the brilliant, pedantic beagle’s solitary childhood and varied accomplishments and another portraying how he found, adopted and raised little orphan Sherman (the characters are voiced by Ty Burrell and Max Charles). It’s to instruct the child about history that Peabody constructs his time-machine, the WABAC (or Wayback, if you prefer); and we see it employed in a visit to the French Revolution, during which dog and son fall afoul of nasty Robespierre (Guillaume Aretos).

The time comes when Sherman must go off to school, however, and on his very first day he earns the enmity of pretty but mean classmate Penny Peterson (Ariel Winter), whose taunts lead him to bite her. Enter belligerent social worker Miss Grunion (Allison Janney), who intends using the incident to take Sherman away from Peabody. In a turn reminiscent of “God of Carnage,” of all things, the dog invites Penny and her parents (Stephen Colbert and Leslie Mann) over to his penthouse digs for an evening where all can resolve their differences, but as the “adults” talk and drink, Sherman and Penny are left to entertain themselves, leading them to take the WABAC for an unauthorized spin.

Thus begins a comic journey through time as Peabody struggles to retrieve the kids before the Petersons find out what’s become of their daughter and Grunion arrives. The first stop is ancient Egypt, where Penny becomes the intended of the young King Tut; the second is a stopover in Renaissance Italy, where Peabody asks his old friend Leonardo da Vinci (Stanley Tucci) for help while Sherman and Penny, who are growing to like one another, try out his flying machine; and the third is the Trojan War, where Sherman joins Agamemnon (Patrick Warburton) and his Greek cohorts inside the wooden horse. Eventually the trio’s efforts to return to the present day while trying not to create a rift in the space-time continuum results in chaos in the New York streets as people and property from epochs long past cascade through a wormhole as the police and Grunion chase Peabody and Sherman down.

There’s a broader arc to all the apparent mayhem—the cementing of the familial bond between Peabody and Sherman, who learn through their adventures to express their love as father and son. It’s doubtful that the acerbic, defiantly unsentimental Ward would ever have been willing to tack such a sweet, sticky moral onto his work. But in this context it comes across as an understandable means of transforming a cult cartoon into the sort warm-hearted family fare that’s obligatory in animated kidflicks nowadays; and it’s forgivable in view of the many bright, clever moments in a picture that isn’t afraid to comment wryly on its own embrace of movie conventions (as in the big emotional finale, when a soupy group hug is interrupted by the hilarious arrival of a character who breaks the mood). Even the mandatory bits of potty humor are more subdued than usual—a reference to a “booby prize” that raises Peabody’s eyebrow, or the sight of characters being expelled from the rear end of a sphinx or a wooden horse.

The saving grace is that “Mr. Peabody & Sherman” follows that other DreamWorks Animation winner, “Shrek,” as well as the Ward template, in upending normal expectations by including a string of off-kilter jokes and sight-gags that come across as different and fresh. Meanwhile it features enough standard-style dewy-eyed moments and full-throated action sequences to satisfy those looking for something fairly familiar. It’s a balancing act Wright and Minkoff have managed with considerable skill.

So has the DreamWorks team, which manages to suggest the oddity of Ward’s original sketches while giving the images the breadth and vividness of contemporary animation—and avoiding the overuse of the 3D possibilities, which are nicely held in check. The voice work is aces as well, with Burrell and Charles making a likable team and folks like Tucci, Warburton, Lake Bell, and even Mel Brooks making distinctive supporting contributions. Danny Elfman’s score also falls pleasantly on the ear, even if it’s not one of his more memorable efforts.

“Mr. Peabody & Sherman” is thus, despite some dead spots, a mostly delightful surprise—an idea that doesn’t seem terribly promising but turns out to be generally engaging and occasionally brilliant. Like “The Lego Movie,” it’s an animated children’s movie too good to be left to a kid audience.