LOS ANGELES — “I don’t know, bro. I was screwed up in the head.”

M. Night Shyamalan, ruminating last month about career choices gone wrong, spoke those words and then burst into a giddy giggle. Just kidding! But the tenderness in his eyes betrayed him: There was some truth in that tease.

In contrast to his first four studio movies, which were all substantial hits, starting with “The Sixth Sense” in 1999, Mr. Shyamalan’s last four films have been a series of misfires. “Lady in the Water,” “The Happening,” “The Last Airbender” and “After Earth” severely tarnished his reputation among moviegoers. The guy who brought us those clunkers — and, yes, we know, “The Sixth Sense” — wants us to buy tickets again?

Pass.

But here comes a hairpin twist nobody anticipated: Mr. Shyamalan, 45, seemingly humbled and more mature, took a hard look at his professional life, made a course correction, and the result, a quirky comedic thriller called “The Visit,” may well deliver a surprise cinematic comeback, or at least the start of one.