Lars von Trier links his hungry woman to philosophical ideas; sex, it turns out, is meaningless without interpretation. Illustration by Concepción Studios

Lars von Trier’s “Nymphomaniac,” a film in two “volumes” (each to be shown separately), is a pornographic work of art—an obsessive, violent, and at times remarkably eccentric sex epic that is often brilliant and never simple-minded or dull. The earlier work of the fifty-seven-year-old Danish director—“Breaking the Waves,” “The Idiots,” “Antichrist”—was soaked in show-off despair. For almost twenty years, he has triumphed on the international art-film circuit as a sensationalist and a boor, making lurid “metaphysical” movies and offering, on one occasion—at Cannes—a hapless pro-Nazi rant. His previous film, “Melancholia” (2011), chronicled the end of the world (a rogue planet wipes us out), something that he appeared to welcome, at least as a visually radiant experience.

But now he has sprung back from the apocalypse to create the fictional history of an insatiable woman. And a personal renewal devoted to that subject raises complicated issues. Saying that a movie is filled with explicit scenes hardly means that it’s trash; there are both artistically challenging and purely exploitative kinds of pornography. Von Trier, working in a rigorously formal style, and adding his own intellectual intricacy to the narrative, couldn’t be farther from the glazed single-mindedness of a routine porn director. “Nymphomaniac,” with its always-searching-for-an-orgasm heroine—her head flung back in posters for the movie—may be ripe for parody, but it passes a basic test: it remains formidable throughout its four-hour length and demanding to think about afterward.

A middle-aged loner, Seligman (Stellan Skarsgård), sees a badly beaten woman, Joe (Charlotte Gainsbourg), lying in a dark alley. He takes her to his flat, gives her tea, and gently asks to hear her story. “I discovered my cunt as a two-year-old,” she begins, and launches into the story of her life as a girl and as a young woman, eventually returning to the present. Her manner is intensely serious, her face unsmiling, her mode of speech self-condemning. “I behaved reprehensibly,” she says. “I was an addict out of lust, not out of need.” As she talks, we see episodes from her life, and, after each one, Seligman offers elaborate, sometimes bizarre observations that provoke Joe into fresh memories. If you sum up her past as a series of would-be realistic events, they immediately collapse into absurdity. From the beginning, however, it’s clear that the story is not a slice of life but something told—interpreted, enhanced, varied, recast. The emotional heart of “Nymphomaniac” isn’t the sex scenes but the conversations between Joe and her protector, which mix artful nonsense, curious semi-nonsense, and startling good sense in daunting profusion.

Who is Joe? She has little history except for her erotic history, little temperament apart from undifferentiated lust. Yet she’s not one of those passive de Sade girls who get hauled off to a château in the forest to be repeatedly violated by lustful men; nor is she like their descendant in “The Story of O.” On the contrary, Joe chooses, she demands, she arranges. In the first part of “Nymphomaniac,” she sleeps with dozens of men, and finally reunites with her first partner, Jerôme (Shia LaBeouf), whom she has come to love. Initially happy with him—she gives birth to his son—she nevertheless announces, in despair, that she has lost any sensation of sexual pleasure. In Volume II, Jerôme urges her to get her groove back by experimenting, and, in a comic episode, she takes up with two African brothers she spies from her window. Then, ever more desperate, she flings herself into masochistic rituals with a professional sadist (Jamie Bell), which is not at all comical—the sessions are re-created in excruciating detail. (Von Trier seems to be saying, “You’re fascinated? Well, stomach this.”) Eventually, Joe falls into bed with a young female protégée (Mia Goth).

The “plot” has obviously been engineered to put Joe through every kind of sex act. Her encounters, in their bounteous variety, would seem to equal those of Catherine Millet, as recounted in her 2002 chronicle, “The Sexual Life of Catherine M.” Both Catherine and Joe have multiple lovers every day for years and yet never suffer the perils of a sexually hyperactive life—disease, death. Millet, recording her own experience, is an exhibitionist and a boaster and, unfortunately, not much of a writer. Von Trier is a filmmaker who uses his art to dramatize not the real world but extreme fantasy. Male or female fantasy? Both, perhaps. Joe may be enacting a darker version of the “Fifty Shades of Grey” saga, but she also represents male imagining. The resented “male gaze” of film theory has become something like awe of a fearless woman who recognizes no other reality but pleasure.

In a blasphemous scene in Volume I, Joe and her high-school friends chant, “Mea vulva, mea maxima vulva” (words that they have written on a wall). When she was a teen-ager, Joe tells Seligman, she wanted to destroy the consumerist enshrinement of “love,” and we see her and a friend smashing the window of a store selling valentine trinkets. In Volume II, von Trier extends the notion of ungovernable female desire as social rebellion; he even morphs into a nineteen-seventies kind of radical feminist. Joe, sacrificing everything to sexual adventure, walks out on Jerôme and their little boy, and at that point she’s wrecking the family, tearing at the basis of society. Sitting with Seligman years later, she speaks of regret and guilt, and he demurs, saying that if she were a man her behavior wouldn’t cause more than a ripple of interest. It’s only as a woman that she’s a revolutionary.

The movie was shot in Germany and Belgium, but it isn’t set anywhere in particular (everyone speaks international English), and the casting is erratic. Propping herself up in Seligman’s bed, Charlotte Gainsbourg, now forty-two, has a smudged, bruised face. She looks like an unhappy child who has been playing in the mud. However badly battered, her Joe is articulate and precise—overprecise, it feels at first, but it becomes clear that the act of telling, from a distance, as a way of exercising control, is as much the point as the tale itself. When the movie switches to the past, however, Joe is a blank. The twenty-three-year-old model who plays her in those scenes, Stacy Martin, has the same long jaw and slender form as Gainsbourg, and, in an early scene on a train, she flashes an engagingly naughty grin as Joe services a solid bourgeois in a first-class compartment. But there’s generally not much going on in her face. Perhaps her director didn’t help her; pursuing his anti-realist aesthetic, von Trier may have wanted her affectless. And Shia LaBeouf, struggling with a vaguely conceived part, looks more unformed than ever; his features are almost fetal. Yet the blankness of the young actors doesn’t kill the movie. Sexual encounters don’t—can’t—complete Joe. Her only true relationship is with Seligman, who offers her release by listening to her.

Seligman is an asexual bachelor and scholar, who lives in a bare apartment that looks like a monk’s cell. He murmurs that Joe suffers from a mistaken sense of sin, that she was just a girl having adventures, giving herself and other people pleasure. Skarsgård is remarkably calm and benevolent, his sixtyish handsome face a landscape of empathy. Seligman likens Joe’s efforts to seduce men to, of all things, fly-fishing, as it is described in Izaak Walton’s classic text, “The Compleat Angler” (1653). And that’s just the beginning. Von Trier has become a virtuoso of baroque elucidation and quasi-absurdist play. When Joe describes her initiation at the hands of Jerôme, Seligman adds up their couplings (front and rear) and says that they remind him of Fibonacci numbers, a series that we later see written on the screen. She takes a turn at exegesis herself. Seligman mentions Bach’s three-part polyphony, with its separate voices creating harmony, and she talks of three men at one point in her life who gave her different things sexually, which amounted to having one complete lover.