I remember little of Insidious besides its Satan’s-jackhammer threnody behind a title card, the Darth-Maul-as-creeper demon, its use of Tiny Tim’s “Tiptoe through the Tulips” for ironic menace, and the mother of a deal director James Wan got on fog machines and empty warehouses for the third act.

However, I’d gladly pony up for the sort of regressive hypnotherapy in which the Insidious films traffic to recall less of Chapter 2, in which Wan’s inability to distinguish patience from tedium was the only terrifying circumstance. (That and Patrick Wilson’s portrayal of a possessed man amounting to aggressive mansplaining.) Perhaps Wan was looking ahead to a billion-dollar franchise that awaited him.

So, not a lot of enthusiasm going into Insidious: Chapter 3, which is to this franchise what last year’s Annabelle was to The Conjuring (another Wan-led horror series). It’s a tangential prequel about a different haunted family that still helps reinforce name-recognition branding. Also as with Annabelle, Wan has relinquished the director’s chair; screenwriter-actor Leigh Whannell, with whom Wan collaborated on Saw, Dead Silence and past Insidious outings, makes his directorial debut here.

Quinn (Stefanie Scott) is an old-soul teenager into the Pixies and P.J. Harvey, adrift among her family after cancer claims her mother. In attempting to contact her mother’s spirit, Quinn has unknowingly drawn the attention of The Man Who Can’t Breathe (Michael Reid MacKay), a persistent ghost whose papery skin and spindly veins complement a death rattle so watery you can almost smell its fetid funk.

As for Whannell’s direction, it’s impossible to miss one bit of botched continuity — a cupcake that keeps disappearing into the mouth of actor Angus Sampson (who, with Whannell, returns as a comic-relief ghostbuster) and reappearing for him to continually devour. But that’s only because Whannell has, by that point, trained our eyes to rivet and dart across the frame, eager to see what peeks out from the edge or what pops up from below.

Whannell, cinematographer Brian Pearson and editor Tim Alverson twist the usual gotcha-scare geometry just off-kilter enough that you’ll jump like it’s your first horror movie. Embarrassing? Maybe. Effective? Absolutely, and the film’s legitimate scares runs the gamut from hammer-cut shocks to broad-daylight moments at which danger’s pace is agonizingly deliberate. Confining the chaos to claustrophobic apartment spaces, rather than a house through which to soar, is also an advantage.

Whannell’s script also takes great care to include nuance with which few modern horror movies bother — palpable, poignant emotional stakes and queries into the psychology of paranormal belief. He examines our view of the afterlife as an antidote to anguishing grief over those who have left us and, in doing so, acknowledges there may be a measure of grace there, too, and not just millions of ghouls.

Perhaps his best decision is yielding the lead role to Lin Shaye, a classic character actress and secret weapon in everything from bawdy comedies to convivial schlock. When we first met Shaye’s Elise Reiner, she was a psychic bravely venturing into the hereafter on behalf of those seeking help. Here, when Quinn approaches her, Elise is a shut-in widow with a murder of crow’s feet clawing at her temples. “Loving someone is just delayed pain,” she says. “We lose them one way or another.”

An obvious prequel problem is that we know Elise won’t stay on the sidelines for long, and that she arrives at a place of power to protect those like Quinn who shouldn’t summon spirits on their own. But Whannell and Shaye inject enough soul to blow past that and make Elise’s journey from fatalism to optimism a compelling one.

Shaye subtly plays Elise’s conscious fears off her nagging curiosity, and the pre-colon title could just as easily refer to an affliction that haunts Elise’s backstory. She’s also matching wits with a particularly venal spirit that takes a trash-talking page, no matter how PG-13-rated, from what a possessed Regan MacNeil told Father Karras his mother liked to do in hell. Mind you, this is a setup you’ve seen several dozen times, but there’s uncommonly eloquent patience to it here. As Elise slowly marshals her resolve, Chapter 3 comes to resemble a thematic mashup of The Babadook and Ghost — facing down life’s hard truths to do what makes the world better.

Whannell also endows what might otherwise be stock supporting characters with intriguing traits. As Quinn’s father, Dermot Mulroney isn’t a bumbling, clueless dolt. He’s a frazzled single parent who’s come to rely on his daughter to be self-sufficient and who bristles, however subconsciously, in the inevitable moments when she can’t be. And his use of the present tense when describing a recently deceased neighbor suggests he’s not as supernaturally skeptical as he seems. There’s even despondency to The Man Who Can’t Breathe’s decrepitude; evil as he is, he still takes time to physically cradle the poor souls trapped in his own personal hell.

As was a failing in Annabelle, you’ll wish Whannell didn’t lean on the Mythical Old Black Woman trope for a deus ex machina moment in the finale. And the tie-ins to Chapter 2, however brief, are bothersome only because they dredge up bad memories of a mess Whannell has otherwise wisely left behind. Still, Chapter 3, easily the series’ best, is an unexpectedly good, gothic summer surprise.