“Hugo,” an enchantment from Martin Scorsese, is the 3-D children’s movie that you might expect from the director of “Raging Bull” and “Goodfellas.” It’s serious, beautiful, wise to the absurdity of life and in the embrace of a piercing longing. No one gets clubbed to death, but shadows loom, and a ferocious Doberman nearly lands in your lap. The movie is based on the book“The Invention of Hugo Cabret,” but is also very much an expression of the filmmaker’s movie love. Surely the name of its author, Brian Selznick, caught his eye: Mr. Selznick is related to David O. Selznick, the producer of “Gone With the Wind” — kismet for a cinematic inventor like Mr. Scorsese.

Mr. Scorsese’s fidelity to Mr. Selznick’s original story is very nearly complete, though this is also, emphatically, his own work. Gracefully adapted by John Logan, the movie involves a lonely, melancholic orphan, Hugo (Asa Butterfield), who in the early 1930s tends all the clocks in a Parisian train station. Seemingly abandoned by his uncle, the station’s official timekeeper (Ray Winstone), Hugo lives alone, deep in the station’s interior, in a dark, dusty, secret apartment that was built for employees. There, amid clocks, gears, pulleys, jars and purloined toys, he putters and sleeps and naturally dreams, mostly of fixing a delicate automaton that his dead father, a clockmaker (Jude Law), found once upon a time. The automaton is all that remains of a happy past.

Hugo has been repairing the automaton with mechanical parts salvaged from the toys he has stolen from a toy store in the station. All that he needs now to bring the windup figure to life — it sits frozen, with a pen at the ready, as if waiting for inspiration — is the key that will open its heart-shaped lock. After assorted stops and starts and quick getaways, Hugo finds the key during an adventure involving the toy-store owner and his goddaughter, Isabelle (Chloë Grace Moretz). A beloved, wanted child, she brings Hugo into her life, which is how he discovers that the cantankerous shopkeeper with the white goatee and sad, watchful eyes is Georges Méliès (a touching Ben Kingsley).

The name means nothing to Hugo and may not mean much to most contemporary viewers, but it means a great deal to this lovely movie. A magician turned moving-picture pioneer, Méliès (1861-1938) began his new career after seeing one of the first public film projections in Paris on Dec. 28, 1895. Until then, early moving pictures had been commercially exhibited on Kinetoscopes, peephole machines that enabled viewers to watch brief films, one person at a time. The image was tiny — less than two inches wide — and moving pictures didn’t become cinema as we know it until wizards like the French brothers Auguste and Louis Lumière created machines like the cinématographe, which projected larger-than-life images on screens that people watched as an audience.

While the Lumières dazzled with nonfiction films that they called actualités, Méliès enthralled with fantasies and trick films like “A Trip to the Moon” (1902). In this comic 16-minute science-fiction masterwork, a gaggle of scientists in knee breeches fly in a rocket to the Moon, where they encounter acrobatic creatures with lobster claws amid puffs of smoke and clever cinematic sleights of hand. In the film’s most famous image, the rocket lands splat in the eye of the Man in the Moon, causing him to squeeze out a fat tear. It was perhaps a prophetic image for Méliès, who, after falling out of fashion and into obscurity, ran a toy store in the Montparnasse station in Paris, which is where he was later rediscovered.

Mr. Selznick opens and closes his book with some soft pencil drawings of Earth’s Moon, that luminous disk on which so many human fantasies (the Man in the Moon included) have been projected. In the book the Moon is something of a screen against which Méliès’s most celebrated cinematic fantasy unfolds. Mr. Scorsese doesn’t exploit this lunar metaphor (perhaps he believes the Moon belongs to Méliès), yet he locates plenty of cinematic poetry here, particularly in the clock imagery, which comes to represent moviemaking itself. The secret is in the clockwork, Hugo’s father says to him in flashback, sounding like an auteurist. Time counts in “Hugo,” yes, but what matters more is that clocks are wound and oiled so that their numerous parts work together as one.

The movie itself is a well-lubricated machine, a trick entertainment and a wind-up toy, and it springs to life instantly in a series of sweeping opening aerial shots that plunge you into the choreographed bustle of the train station. The first time you see Hugo he’s peering out from behind a large wall clock at the human comedy in the station. He’s staring through a cutout in the clock face, an aperture through which he watches several characters who play supporting roles in a spectacle that is by turns slapstick, mystery, melodrama and romance, including the menacing station inspector (Sacha Baron Cohen), a friendly flower vendor (Emily Mortimer), a woman with a dachshund (Frances de la Tour) and her suitor (Richard Griffiths). When Hugo gazes at them, he’s viewer and director both.

So much happens in this initial whoosh that it feels as if you’d hitched a ride on a rocket too. After the camera divebombs through the station, it follows Hugo as he speeds down halls, a ladder, a chute, a staircase and yet more halls, bringing to mind a Busby Berkeley set and Henry Hill’s long walk into the nightclub in “Goodfellas.” The camera keeps moving, as does Hugo, who, chased by the station master and his Doberman, sprints past James Joyce and Django Reinhardt lookalikes. It’s Paris of the Modernist imagination, though really it’s movieland, where gears loom like those in “Modern Times” and a man who’s part machine oils his bits like the Tin Man (while longing for a heart).

An error has occurred. Please try again later.

You are already subscribed to this email.

Mr. Scorsese caps this busy introductory section with Hugo looking wistfully at the world from a window high in the station. The image mirrors a stunning shot in his film “Kundun,” in which the young, isolated Dalai Lama looks out across the city, and it also evokes Mr. Scorsese’s well-known recollections about being an asthmatic child who watched life from windows — windows that of course put a frame around the world. This is a story shared by all children, who begin as observers and turn (if all goes well) into participants. But “Hugo” is specifically about those observers of life who, perhaps out of loneliness and with desire, explore reality through its moving images, which is why it’s also about the creation of a cinematic imagination — Hugo’s, Méliès’s, Mr. Scorsese’s, ours.

“Hugo” is the tale of a boy, one of fiction’s sentimental orphans, and the world he invents, yet, unsurprisingly, its most heartfelt passages are about Méliès. The old filmmaker is as broken and in need of revival as the automaton, and while you can guess what happens, it’s the getting there — how the clock is wound — that surprises and often delights. Waves of melancholy wash over the story and keep the treacle at bay, as do the spasms of broad comedy, much of it nimbly executed by Mr. Baron Cohen. There is something poignant and paradoxical about Mr. Scorsese’s honoring a film pioneer in digital (and in 3-D, no less), yet these moving pictures belong to the same land of dreams that Méliès once explored, left for a time and entered once again through the love of the audience.

“Hugo” is rated PG (Parental guidance suggested). The death of a parent, some child peril and a fierce dog.

HUGO

Opens on Wednesday nationwide.

Directed by Martin Scorsese; written by John Logan, based on the novel “The Invention of Hugo Cabret,” by Brian Selznick; director of photography, Robert Richardson; edited by Thelma Schoonmaker; music by Howard Shore; production design by Dante Ferretti; costumes by Sandy Powell; visual effects supervisor, Rob Legato; produced by Graham King, Tim Headington, Mr. Scorsese and Johnny Depp; released by Paramount Pictures. Running time: 2 hours 6 minutes.

A film review on Wednesday about “Hugo,” the new Martin Scorsese movie, misstated its rating in some copies. It is PG (parental guidance suggested), not PG-13 (parents strongly cautioned). And a listing of credits with the review misstated the film’s running time. It is 2 hours 6 minutes, not 2 hours 30 minutes.

A version of this review appears in print on November 23, 2011, on Page C1 of the New York edition with the headline: Inventing A World, Just Like Clockwork. Order Reprints|Today's Paper|Subscribe