Just when it seemed that Woody Allen had lost his touch, producing a string of movies high on curdled whimsy, recycled jokes and pallid dramatics, he surprises with one of his richest, most incisive films in years. Much of the credit for “Blue Jasmine” goes to him, but he has to share it with his fine ensemble cast and especially Cate Blanchett, whose lead performance is a marvel.

Allen’s script is obviously a riff on “A Streetcar Named Desire,” but with a contemporary twist. Jeanette (Blanchett), who’s taken to calling herself Jasmine, was for years the pampered wife of Wall Street mastermind Hal (Alec Baldwin), living a life of privilege and ease in New York high society. But her husband was arrested on charges of securities fraud and committed suicide in jail, and her relationship with his son Danny (Alden Ehrenreich) collapsed. Now penniless and fraught, she arrives in San Francisco to stay with her sister Ginger (Sally Hawkins)—who’s actually not a blood relative, since both were adopted from separate birth parents—until she can get back on her feet.

Of course Jasmine is hardly the sort to pull herself out of the doldrums on her own power. Nervous and demanding, still nursing a sense of noblesse oblige though fallen on hard times, prone to bouts of clinical depression, and more inclined to empty dreams of becoming an interior decorator than taking a mundane job, she’s the epitome of the high-strung, self-absorbed woman accustomed to being taken care of and considering it her due. By contrast Ginger’s a struggling single mother to two young sons and a check-out clerk at a supermarket. Her ex-husband Augie (Andrew Dice Clay) is a rough-and-tumble handyman who lost his windfall—a lottery jackpot—in a scheme of Hal’s and can’t believe Jasmine’s protestations that she knew nothing of her husband’s illegalities. And she’s now hooked up with Chili (Bobby Cannavale), a gregarious but boorish mechanic whom Jasmine immediately writes off as a loser unworthy of Ginger.

The film proceeds in fits and starts, jumping between the California present and the East Coast past. It gradually offers a portrait of Jasmine’s former life, revealing Hal’s serial infidelity as well as Ginger’s discovery of it during the visit on which Hal wheedled Augie’s money out of him. But the bulk of it is devoted to the sisters in San Francisco. There Jasmine, after putting off a low-class chum that Chili proposes as a possible boyfriend, takes an unsatisfying job as receptionist to a nebbishy dentist (Michael Stuhlbarg) who develops a crush on her. Meanwhile she tries to learn computer programming, to little avail, and encourages Ginger to dump Chili in favor of a decent-seeming sound engineer (Louis C.K.) she meets at a party—sending Chili into an uncontrollable rage. Ginger’s new relationship doesn’t turn out quite as she hoped, nor does Jasmine’s romance with slick State Department up-and-comer Dwight (Peter Sarsgaard), who accepts her airs and even goes so far as to propose, until Jasmine’s lies about her past derail the happy ending she’d envisaged for herself.

Unlike in so many of his films, Allen balances dark humor and sharp drama meticulously here, with an emphasis on the latter. And he’s supremely fortunate to have Blanchett in the lead. She fully embodies the desperation of Jasmine as the character veers from vodka-soaked self-delusion to contemptuous dismissal of those she considers inferior and from morose introspection to babbling hysteria. The range of emotions the script demands of Blanchett is enormous, and she responds with a ferocious performance that captures all of them. Hawkins has a much less demanding role, but she captures Ginger’s vulnerability well, and Baldwin is the very essence of the calculating shark. Of the other men in the cast, Cannavale and Clay strike all the right notes as lower-class guys with volatile tempers, while Sarsgaard draws an impeccable portrait of the consummate class-conscious Washington insider. And though Louis C.K. doesn’t have much screen time, he’s surprisingly convincing as a guy who might not be as nice as he seems. Even Stuhlbarg manages to give some depth to what might have been a mere caricature.

“Blue Jasmine” exhibits the unobtrusively excellent technical quality of most Allen movies, with cinematographer Javier Aguirresarobe making fine use of the outdoor locations as well as the very different interiors—from plush, expensive apartments to cramped, overfilled ones. And the song “Blue Moon” was an inspired choice as a signature melody, its melancholy tones capturing the longing for love that’s the key to Jasmine’s character while also suggesting a larger cultural context (it was written in the throes of the Depression, and somehow suggests the equally disorienting economic realities of the present). This is both a sharp-edged character study of a woman on the verge of a psychological breakdown and a cannily-constructed ensemble piece reflecting the differences of class and culture that permeate American life.