“Stardust” might be the “Princess Bride” of its generation: a darkly comedic and imaginative fairy tale full of witches, princes, and magic spells, not to mention a happily-ever-after ending. The story (based on a book by Neil Gaiman) is bursting with memorable characters and sly wisdom, with heroes you can love and villains you can love hating. A couple of small missteps aside, it’s one of the most purely delightful movies of the year.

Our hero is 18-year-old Tristan Thorn (Charlie Cox), an unremarkable but good-hearted lad in the 19th-century English village of Wall. He is in love with the vain Victoria (Sienna Miller), and when they see a falling star one night, he vows to bring the star to her as a token of his love. In exchange for this, she says she will marry him.

The star has fallen on the other side of Wall’s wall, in an enchanted land called Stormhold, and Tristan is surprised to learn that stars have a human shape. This one, named Yvaine, has the shape of Claire Danes. She finds Tristan rude at first, and Tristan has eyes only for Victoria, but they can help one another here: Tristan has a magic candle (bequeathed by his long-lost mother) that can get Yvaine back to the heavens where she belongs, and he agrees to let her use it if she’ll accompany him back to Wall and let him show her to Victoria.

Other people want Yvaine, too, though. The king of Stormhold (Peter O’Toole) is dying, and the throne will go to whichever of his sons can 1) get the ruby that is now in Yvaine’s possession, and 2) avoid being killed by his brothers. The Stormhold princes have a tendency to murder one another, you see. Their ghosts, still bearing the marks of the way they were killed, are doomed to hang around, observing and commenting and continuing to quarrel, until the matter of heirship is settled.

Furthermore, a trio of ghastly witches needs the star’s glowing heart to recharge their youth and beauty, which has withered dramatically in the 400 years since they last got a boost. One of these sisters, Lamia (Michelle Pfeiffer), sets out in search of Yvaine, disguised as a younger, beautiful woman. She must use her magic sparingly now, as each spell she casts chips away at her disguise.

I’ll leave the details of the adventure alone and let you be surprised by them, by their daftness and ingenuity. Animals turn into people; people turn into animals; ships sail the skies to capture lightning; heroes engage in swordfights with dead men; a nonagenarian proves skilled in hand-to-hand combat; a prince bleeds actual blue blood. And that barely scratches the surface of the story’s eccentric, thoroughly entertaining details.

There are events in the tale that suggest a great deal of twisted creativity went into it — first from Gaiman, and now from the film’s director, Matthew Vaughn, whose only previous film, the gritty crime caper “Layer Cake,” used his eye-catching visual style for much darker purposes.

The film’s weak points, I think, are its two major bits of stunt casting: Ricky Gervais (England’s “The Office”) as a lowlife merchant, and Robert De Niro as a mean pirate with a soft side. Gervais plays the same unctuous character he always plays — i.e, more or less himself — and this is in contrast to the film’s other actors, most of whom are trying to play actual characters. (Michelle Pfeiffer, for example, is so fearless and funny as the evil witch, in all her varying degrees of grossness, that you almost wish the film were about her.)

De Niro, meanwhile, plays on both of his reputations: that of a tough guy, and that of a guy who likes to make fun of his tough-guy reputation. He overdoes the latter aspect, earning laughs that are hearty but cheap, like a character in a lowbrow sketch-comedy show. I’m not saying it’s not funny; I’m just saying it doesn’t fit in this movie. It throws us off-course for a while, and the film has trouble getting back on track.

But everything else is nearly perfect, an utterly beguiling, magical film from start to finish, with a lovely musical score by Ilan Eshkeri to boot. It’s ultimately a love story, naturally, as Tristan and Yvaine grow fond of each other during their travels and adventures. I find their romance touching, in its fairy-tale-template way, and though the happy ending is as predestined as in any Grimm fable, that doesn’t make it any less sweet when it arrives. The joy is in the journey, and “Stardust” has a lot of joy in it.

B+ (2 hrs., 10 min.; PG-13, moderate violence, a little innuendo and naughty humor.)