To all of the shocking developments of the last 12 months, we may now add yet one more: M. Night Shyamalan has made a good movie.

Or perhaps that’s overstating it a bit. The writer-director’s latest offering, Split, is more good-bad, a B-movie that earns itself no better than a solid B. That said, given the precipitous grading curve down which Shyamalan has been slaloming for well over a decade, this is a moderately remarkable achievement.

A quick recap, for those who may have forgotten. After breaking into public consciousness with the celebrated The Sixth Sense in 1999, Shyamalan followed up with the quite-good Unbreakable, and the intriguing but not-quite-successful Signs. And then his filmmaking promptly fell off a cliff: The Village, Lady in the Water, The Happening (so terrible that it necessitated inventing the “spoilereview”), The Last Airbender, and After Earth. His most recent film, 2015’s The Visit, was less awful than its predecessors and therefore widely mistaken for being good, which it wasn’t.

But now, with a very notable assist from actor James McAvoy, Shyamalan has succeeded in making a movie that’s actually worth seeing, at least for those in the proper mood. McAvoy stars as “Kevin”—or rather, as someone who was long ago known as “Kevin.” Over the subsequent years, his psyche has fractured into 23 distinct personalities, some of them more unpleasant than others.

The movie opens with one of these personalities, Dennis, abducting three high-school girls from a birthday party at a mall in King of Prussia, Pennsylvania. Two of the victims (Haley Lu Richardson, Jessica Sula) are well-adjusted, popular girls; the third—and principal protagonist—is a loner with psychic scars of her own (Anya Taylor-Joy, from last year’s The Witch). Dennis locks them away in a windowless room and tries to indulge his penchant for watching young women dance in various stages of undress.

He is quickly reprimanded, however, by a stern woman, Patricia, who—in an ostentatious nod to Psycho—turns out to be another of Kevin’s many personalities. Off come Dennis’s glasses, on goes Patricia’s necklace and, boom!, the James McAvoy Masters Class in Acting is underway. Soon, we’ll also be introduced to Hedwig, a self-described 9-year-old boy; and Barry, a fashion designer who serves as the public face of the burgeoning menagerie.

Patricia chides Dennis for his naughty behavior with the girls, reminding him that they have been seized for another, greater purpose, at the behest of an as-yet-unseen personality. And so begins the game of cat and mice: The girls try to escape by playing the alternating trio of Dennis, Patricia, and Hedwig off one another, and Dennis/Patricia/Hedwig tries to keep them under lock and key.

Meanwhile, Barry, the “good” personality, plays his own, less malevolent cat and mouse with the psychologist and specialist in Dissociative Identity Disorder (Betty Buckley) whom he regularly visits. But the more he tries to assure her that all is well with the gang in Kevin’s head, the more he persuades her that something is going very wrong.

For its first two-thirds or so, Shyamalan keeps Split admirably creepy and well-paced, eliciting a nice performance from Taylor-Joy and solid ones from the rest of the supporting cast. (Buckley, in particular, was owed a decent role in recompense for the awful one Shyamalan saddled her with in The Happening.)

The movie falls out of kilter in the final act, however. An unsavory backstory regarding Taylor-Joy’s character that appeared to be completely unnecessary is instead revealed to be a component of the movie’s painfully Shyamalanian final twist. (Seriously, dude. Not every one of your movies needs one of these. Consider this an intervention.) Moreover, once the film’s ultimate villain is unveiled, what ought to have been a 10-minute finale is stretched to twice that. (There is, however, an unexpected Easter Egg at the end for Shyamalan aficionados.)

But the director’s strengths and weaknesses aside, it’s McAvoy’s performance(s) that elevate the film above its otherwise low-horror potential. (I was reminded of Edward Norton’s breakthrough role in Primal Fear, another B-movie elevated by an A+ split-personality performance.) In each of the “characters” McAvoy inhabits, he finds sparks of charm and wit—elements that have all too often been lacking in Shyamalan’s oeuvre. “He did awful things to people and he’ll do awful things to you, too,” the pre-adolescent Hedwig warns the kidnapped girls, before quickly adding, “I have blue socks.” And the twinkly delight that Patricia takes in a sandwich she has made for the girls—“It’s good. It’s got paprika”—is positively contagious.

Thanks largely to McAvoy, Split is easily Shyamalan’s best film since Signs, and perhaps even Unbreakable. Moreover, along with The Visit, it suggests an obvious path for him moving forward. It may be the case—indeed, it certainly looks to be—that Shyamalan will never again rediscover the elegance and control he displayed so early on in The Sixth Sense. But the world needs second-tier, quasi-guilty-pleasure entertainments, too. And with Split, Shyamalan may have finally found himself the productive niche that eluded him for so long.