On the closing night of the 71st Cannes Film Festival, the score to The Man Who Killed Don Quixote boomed out across the Croisette from the Palais des Festivals. At the top of the steps, surrounded by his cast, Terry Gilliam waved his arms with a devilish joy, mock-conducting the music to his film in defiance of the decadeslong, seemingly cursed journey it took to get it made, let alone seen.

All that joy—and pain—is in the film itself. First conceived as a pared-down adaptation of Cervantes’ novel, Gilliam’s white whale has morphed into a film about film. It even opens on a film set, as Toby (Adam Driver) directs a commercial loosely modeled on the famous scene in which Don Quixote, an old nobleman who has become so obsessed with the notion of chivalry that he loses his mind, battles windmills, believing them to be giants. As Toby struggles to complete the shoot, he discovers a copy of his student film, an adaptation of Don Quixote, and decides to return to the Spanish village where he’d shot it—it’s called Los Sueños, or “Dreams,” a clear indicator of the level of earnestness at which Gilliam is operating—to seek inspiration.

The fractured and desperate community that he finds is described by different characters in contradictory terms—“sweet,” “sad,” “broken,” “martyrlike”—all fitting the former subjects of his film, who were irrevocably changed by the experience, and applying just as easily to Gilliam’s film itself. Gilliam’s work has always teemed with contradictions and dichotomies, and in The Man Who Killed Don Quixote, he brings them to a dizzying, exhilarating high, taking failed and deluded creatures and raising them into something holy. It would have been easy for Gilliam to succumb to cynicism given the cavalcade of misfortune that has befallen the film—and still does, with a former producer’s lawsuit threatening to derail the premiere. (A title card before the film, met with cheers, said the screening would not affect the ongoing legal battle.) Instead, he’s created a film suffused with a love of art, and of those who would dare to make it.

It helps that he’s cast Jonathan Pryce as his Don Quixote—or rather, as a shoemaker named Javier, who came to believe he truly was the knight errant after starring in Toby’s film. Three decades on from Brazil but still as spry as anyone else in the cast, Pryce is the perfect avatar for the borderline insane hopefulness that the making of art requires. Even with a prosthetic nose, his features sit between joyous and mournful, and he still has one of the most romantic voices in show business, despite the fact that half of the words coming out of his mouth are pure delusion.

In a telling move, that delusion doesn’t extend to the bright-eyed Angelica (Joana Ribeiro), who played Quixote’s love, Dulcinea, in Toby’s film; even when Javier sees her again, he doesn’t confuse her with the real (fictional) thing. His Dulcinea is intangible, an ideal for whom he is striving and (happily) suffering. As the skeptical Toby becomes more and more involved in Javier’s grand fantasy, the film weaves in and out of fantasy until the distinction between waking and dreaming is impossible to pinpoint. Such, too, is Gilliam’s pursuit.

At the press conference preceding The Man Who Killed Don Quixote’s premiere, Pryce recalled watching Lost in La Mancha, the 2002 documentary about Gilliam’s failed first attempt at making the movie, in tears, while the audience around him laughed. (To be fair, both reactions are understandable, in so far as the trouble that the production experienced ranged from scheduling conflicts to the kinds of natural disasters that could easily be termed acts of God.) Pryce joked, too, that the real reason that the film had taken so long to get made was because Gilliam had been waiting for him to age into the lead role—a bittersweet line given the completed film’s dedication to Jean Rochefort and John Hurt, both previously cast as Gilliam’s Quixote, neither of whom lived to see the film completed.

Similar reminders of The Man Who Killed Don Quixote’s long journey to the screen are scattered throughout, from the title card (“And now … after more than 25 years in the making … and unmaking”) to the way the would-be Quixote’s fantasies are constantly pulled out from under him. Unfortunate though it is, it feels almost fitting that the film still isn’t completely out of the woods. Gilliam himself is still in hot water after comparing the #MeToo movement to “mob rule,” and though the film opened in theaters in France on the same night that it premiered at Cannes, it was dropped by its American distributor, Amazon Studios, on the day the festival began. (News of the latter roughly coincided with reports that Gilliam had suffered a stroke, although he later clarified it was a perforated artery).

The tale of Don Quixote is a mixture of tragedy and triumph, but in the balance, triumph wins out. Or at least, it did at Cannes, where the film drew a standing ovation that lasted long enough that Gilliam began, in jest, to gesture at his watch and feign sleeping. Despite tongue-in-cheek fears that the Palais might be hit by a meteor or its screen might spontaneously burst into flame, The Man Who Killed Don Quixote was officially out in the world, its wondrous dream finally bleeding into reality. To quote the film itself: Quixote vive.