An air of Hitchcockian menace and free-floating sexual perversity is by now nothing new for Francois Ozon, but rarely has this French master analyzed the cracks in his characters’ bourgeois facades to such smooth and pleasurable effect as he does in “The New Girlfriend.” A skillfully triangulated psychological thriller about a woman who learns that the husband of her deceased BFF is harboring a most unusual secret, this delectable entertainment is as surprising for its continually evolving (and involving) dynamics of desire as for its slow-building emotional power, making for a warmer, more open-ended experience than the creepy Ruth Rendell tale from which it’s been “loosely adapted.” Powered by beautifully controlled performances from Anais Demoustier and Romain Duris, Ozon’s “Girlfriend” should have willing arthouse escorts lining up worldwide. It opens Nov. 5 in France.

Rendell, that icy master of British detective fiction, has been best served onscreen by European filmmakers outside the U.K., at least on the evidence of Claude Chabrol’s “La Ceremonie” and Pedro Almodovar’s “Live Flesh.” Viewers may well recognize some signature Almodovarian flourishes in this particular saga of gender subversion and forbidden lust; in significantly reshaping Rendell’s taut, chilling short story (mainly by killing off a key character and adding an infant to the mix), Ozon has effectively transformed the material into a clever fantasia on the many varieties of sexual perversity. It will require some mental gymnastics on the viewer’s part to keep up with the increasingly unstable laws of desire that govern the second act, but the director crucially maintains a lifeline to reality even when things threaten to go deliciously over-the-top.

From the moment they seal their bond in blood to their respective weddings some years later, childhood best friends Claire (played as an adult by Demoustier) and Laura (Isild Le Besco) are utterly inseparable. And so it comes as a particularly devastating blow when Laura becomes ill and dies, leaving her husband, David (Duris), to raise their newborn daughter, Lucie, by himself — albeit with help from godmother Claire and her spouse, Gilles (Raphael Personnaz). All this is compressed into a marvelously economical opening sequence, marked by a distinctly Brian De Palma vibe with its elegant camera moves and morbidly beautiful overhead shots of Laura’s impeccably dressed corpse, plus the mildly unnerving sense that the film is simultaneously mourning and mocking its characters’ unhappiness, as signaled by the swoons and sobs of Philippe Rombi’s extravagantly soapy score.

Once things quiet down and life returns to a normal rhythm, Claire resolves to cope with Laura’s passing by helping on David and the baby as often as possible. When she stops by the house one afternoon and finds the door unlocked, she enters to see Lucie being cradled in the arms of an unfamiliar woman — who, on closer inspection, turns out to be none other than David, wearing makeup, a blonde wig and one of Laura’s old dresses. Claire is shocked, to say the least (“You’re a pervert,” she tells him), but she seems less disgusted than curious and intrigued, and David opens up to her about his longtime compulsion to dress as a woman — a compulsion that had nothing to do with sexual orientation (he’s not gay), and which receded when he married Laura, but returned in the weeks following her death.

The fact that Lucie seems to respond positively to David in drag seems justification enough for him to continue doing it, and indeed, the degree to which Laura’s ghost hovers over the proceedings is what makes the picture at once so disturbing and so weirdly moving, as if David’s decision to channel his late wife’s appearance were a way of keeping her alive. It’s not long before Claire finds herself fully complicit in both shielding and enabling David’s secret life, going out to the mall with “Virginia” (as they begin calling his feminine alter ego), allowing her to become comfortable with herself and with those around her. Meanwhile, Claire keeps the truth from Gilles, her vague sense of guilt unassuaged by the fact that she and David are not, strictly speaking, having an affair.

Even as “The New Girlfriend” develops into a richly suggestive essay on the complexity of sexual identity and the mutability of desire, Ozon readily invites the viewer to see the humor in the situation, particularly when David, forced to change back into men’s attire by an unexpected visitor, forgets to wipe off his lipstick or to stifle an effeminate hand gesture. Remarkably, however, it takes almost no time at all for us to get used to Virginia, and indeed to see her as David’s most natural manifestation — a gambit that works in no small part because Duris, with his slender frame and soft, delicate features (apart from the somewhat distracting front teeth), looks undeniably good in a dress. But physical persuasiveness turns out to be merely the most obvious facet of the actor’s subtle and moving turn as a man not quite ready for his identity to be reduced to that of a loving father and grieving widower.

It’s a measure of the film’s accomplishment, and of Demoustier’s keenly intelligent performance, that Claire becomes no less fascinating a character, and she’s soon forced to confront her own developing feelings for David/Virginia, which are neither really sexual nor entirely innocent in nature. If Duris is the actor whose gender-bending antics send the film spinning into giddy realms of outlandish possibility, then Demoustier (having an outstanding year as the star of this film and Pascale Ferran’s marvelous “Bird People”) is the one who keeps it grounded and persuasive. So, too, does Personnaz in the relatively thankless but still-crucial role of Claire’s husband, an unimaginative, somewhat conservative-minded guy amid a swirling sea of sexual confusion.

Ozon’s view of the situation is wondrously fluid: Convenient explanations like “homosexuality” and “transvestism” (and darker ones like “necrophilia”) hover teasingly over the story like thought balloons, but nothing is decisively pinned down in a film that likes to indulge multiple interpretations without settling on any one in particular. At the core of the story is the shifting balance of power, lust and femininity between Claire and David/Virginia: It’s no accident that when Claire and Virginia are out together in public, Virginia is the one who turns heads — a fact that the film underlines by subtly coding Claire as masculine at every turn, whether by clothing her in a dark coat that almost resembles a tuxedo next to Virginia’s brightly colored dress (the fine handiwork of costume designer Pascaline Chavanne), or by having her suddenly take on a much more aggressive role in the bedroom with Gilles.

Pristinely lensed by d.p. Pascal Marti, with a particularly fine eye for the contours of human flesh, the film does lose some of its artful balance in the increasingly delirious second act, piling on the fake-out dream sequences en route to a hotel-room confrontation more explosive than anything that happened behind closed doors in the director’s prior film, “Young & Beautiful.” But even as he heads down any number of tantalizing if borderline-nonsensical alleyways, Ozon maintains his diabolical wit, his infectious sense of play and his essential affection for his characters, including those who may exist only in a theoretical sense (like Laura and Virginia), but who refuse to be stifled nonetheless. By the end, “The New Girlfriend” seems descended less from the grand tradition of cross-dressing farces than from the melancholy lyricism of “Being John Malkovich,” right down to a final shot that feels unsettled, ambiguous and strangely right.

I wholeheartedly agree with your review, which I read right after submitting my IMDb comment. A return to form for Ozon, whose output has been hit ‘n miss ever since his English language car crash Angel back in 2007. In fact, quite possibly his best film yet.