Visionary director Terry Gilliam (“Brazil,” “Time Bandits”) swings for the fences in “The Imaginarium of Dr. Parnassus,” a mostly successful but uneven film about an ancient storyteller struggling to gain immortality through his wild narratives. Featuring the final performance by Heath Ledger, “Parnassus” is immense in visual scope and constitutes a return to form for Gilliam.

The story centers around Dr. Parnassus (Christopher Plummer), a 1,000-year-old storyteller who was granted immortality for winning a bet with the Devil (played, here, by a nefarious, mustachioed Tom Waits). Once a revered monk, we meet up with Parnassus after the years have taken their toll on him, and he is reduced to a poor, traveling performer. His theater troupe goes from block to block by horse-drawn carriage peddling Parnassus’ Imaginarium experience. Parnassus is plagued by his addiction to betting with the Devil, who shows up at the start of the film to collect his greatest prize: Parnassus’ young daughter, Valentina (Lily Cole). The Devil gives Parnassus one more gamble in order to save her: the first to collect five souls wins.

Those who enter the Imaginarium via Parnassas’ enchanted mirror are sent onto a journey into their own imaginations, using Parnassas as a conduit. Once inside, they are eventually forced to decide whether they are brave enough to explore the potential of their own subconscious.

Gilliam has always specialized in fantasy films and is no stranger to fairy tales — or psychedelia, for that matter — but he has had trouble, as of late, in combining the two. “The Brothers Grimm” and the out-there “Tideland” struggled to be thought provoking and, quite often, struggled to be coherent. This film, while similarly self-indulgent and often lacking logic, is a return for Gilliam to some of his old tricks.

As in “Brazil” and “Time Bandits,” arguably Gilliam’s best films, “Parnassus” purports the death of the imagination at the hands of commercialism and social conceptions of normalcy. Also, “Parnassus,” although highly computer generated, has a much more tactile and three-dimensional visual style, as Parnassus’ traveling show seems like a whimsical pop-up book and is reminiscent of Gilliam’s early pre-CG-saturated films and even some of his early work with “Monty Python.”

Interestingly, the film feels extremely personal for Gilliam, who, through “Parnassus,” seems to be explicating his own plight as an often struggling storyteller, trying to capture our imaginations and save us from the devil who, for the sake of metaphor, I’ll refer to as James Cameron and his hollow temptations. To the viewer, Parnassus and the devil are not so much battling for our soul but for the suspension of our disbelief, which, and I’m sure Parnassus would agree, is close to the same thing.