You can see the fingerprints of both director Michael Bay and executive producer Steven Spielberg all over “Transformers,” an often-mesmerizing family film inspired by the Hasbro line of changeable toys and a 1980s animated TV series.

Bay’s previous, ambitious spectacles (“Armageddon,” “The Island”) were marred by crassness and sprawling storylines. While Spielberg’s well-crafted family films (“Close Encounters of the Third Kind,” “E.T.”) were marked by a self-effacing sense of humor.

For the most part, “Transformers” remains disciplined and engaging even as it punctuates relentless energy with frequent sight gags, parodies and sketch humor. The whole enterprise briefly threatens to become unhinged around the halfway mark (when John Turturro mockingly enters as an overbearing intelligence agent). But “Transformers” quickly rediscovers its bearings in time for an extraordinary third act that sets a new standard for marrying visceral human action with thrilling computer-generated effects. Its climactic battle sequence recalls another Spielberg triumph, “Saving Private Ryan.”

At the center of the hoopla is Shia LaBeouf in a starmaking role as Sam Witwicky, a socially awkward adolescent who gets into the thick of a galactic war between rival clans of aliens. An item Sam puts up for sale on eBay, a pair of glasses that belonged to his great-grandfather, is feverishly sought by both the heroic Autobots and villainous Decepticons, giant robots that can quickly metamorphose into trucks, sports cars, tanks and even cellphones.

Most Read Stories

Kids of all ages who are passionate about their Transformer toys understand how turning one thing into another thing is a deeply satisfying and basic form of play. “Transformers” sticks to the spirit of that pure experience, dazzling us with living machines that restructure themselves constantly. They rage around the deserts of Qatar and streets of an American city; one folds into a jaunty Camaro that self-propels Sam and love interest Mikaela (Megan Fox) through dangerous nights.

Among the voices of the animated Autobots and Decepticons are Peter Cullen (who also worked on the TV show) as noble Optimus Prime and Hugo Weaving (“The Matrix”) as the evil Megatron, the latter searching for a mysterious cube whose whereabouts lead to some imaginative, revisionist American history. A hammy performance by Jon Voight as a distraught secretary of defense and funny turns by Kevin Dunn and Julie White as Sam’s anxious if well-meaning parents are just plain fun — as is the script’s foray into the “real” reasons behind the creation of the Hoover Dam and microchip.

The only thing lacking in “Transformers” is the sense of event that Spielberg captured during the initial alien attack in “War of the Worlds.” As with that film, it’s hard not to see “Transformers” — with its Gulf War veteran troops fighting agents of terror on U.S. soil — as an allegorical reflection of contemporary fears. If the film had pushed that envelope a little more, even subconsciously, “Transformers” might have been an instant classic. But for what it is — an unexpectedly witty and exciting movie quick on its feet — it’s a blast.