Nana and Pop Pop (Deanna Dunagan and Peter McRobbie) welcome the grandchildren they’ve never met into their home. (Universal Pictures)

Measured against the low expectations that the name M. Night Shyamalan has come to engender in the hearts and minds of his former fans, “The Visit” is a triumphant return to form for the filmmaker of “The Sixth Sense,” whose once-promising career has steadily declined for at least the past decade. The new film is an effective if flawed psychological thriller, a modest campfire story with a solid, genuinely startling twist that is likely to restore the faith of some of his critics.

Two teenagers have come to rural Pennsylvania to visit their mother’s parents — in fact, to meet them for the first time. No sooner have 13-year-old Tyler and his older sister Becca (Ed Oxenbould and Olivia DeJonge) arrived in the home of Nana and Pop Pop (Deanna Dunagan and Peter McRobbie) than the old folks start acting funny. Nana wanders around the spooky old farmhouse after dark, clawing at doors; Pop Pop is incontinent and forgetful. To a child, that’s understandably disturbing. To anyone who knows anything about age-related dementia and “sundowning” — the confusion sometimes experienced by seniors at night — it’s not that big a deal.

But Shyamalan’s script gradually cranks things up. By the end of Tyler and Becca’s week in the country, their grandparents really seem to have lost their marbles, setting the story up for the doozy of a corkscrew turn that’s coming. If it takes Shyamalan a while to get to that juncture — and it does; there are moments when “The Visit” is almost painfully dull — the payoff is worth the wait.

Siblings Tyler and Becca (Ed Oxenbould and Olivia DeJonge) voice concerns about their grandparents’s behavior to their mother (Kathryn Hahn). (Universal Pictures)

Shyamalan has always had a flair for visual storytelling, even when his plots have been over-the top, as in “Lady in the Water,” or lacking, as in “The Happening.” Here, however, he throws flashy camerawork out the window, resorting to the lazy cinematographer’s trick of found footage. (The conceit of “The Visit” is that Becca, an aspiring filmmaker, is shooting a documentary about her mother’s childhood home, with the assistance of her younger brother. Mom, played by Kathryn Hahn, is seen mainly via videoconference on Becca’s laptop. “No one gives a crap about cinematic standards,” cracks Tyler, in one of many inside-joke lines exchanged between the adolescent filmmakers in this celebration of the shaky camera.)

In addition to its slowness and general ugly visuals, “The Visit” has other problems. For a long time, it’s only sort of scary, sort of funny and sort of poignant. A back story about the children’s estranged father — whose marriage to their mother caused a rift in her relationship with her parents — feels like a distraction for much of the film. In the end, however, Shyamalan makes that broken family dynamic work for the story, enriching and deepening a tale that could easily have been just another cheesy horror story.

The cast of mostly unfamiliar actors also serves “The Visit” well. Shyamalan has a gift for eliciting strong performances, even when his material is lacking. When one of his spooky bedtime stories is at full boil — as it is in “The Visit’s” final, dementedly fun third act — there’s just no stopping him.

PG-13. At area theaters. Contains frightening images, brief nudity and coarse language. 94 minutes.