Multiple personality disorder, like amnesia, is one of those aberrant mental states that has been a curse to those who suffer, but a gift to screenwriters over the years. From Alfred Hitchcock’s “Psycho” to Brian De Palma’s “Dressed to Kill,” filmmakers have long exploited how little we truly understand about the condition — though none has pushed it quite as far as M. Night Shyamalan does in “Split,” treating dissociative identity disorder not as the twist, but as the premise on which this wickedly compelling abduction thriller is founded: James McAvoy plays a lunatic kidnapper with at least 23 personalities to his name.

Rest assured, there are plenty of proper twists to follow, none more unexpected than the fact that Shyamalan himself has managed to get his groove back after a slew of increasingly atrocious misfires. To be fair, it’s hard to imagine any writer/director sustaining a career based almost entirely on surprising audiences. And though he lost us for a while there — water-intolerant aliens, anyone? — by trading on ingenuity rather than big-budget special effects, Shyamalan has created a tense, frequently outrageous companion piece to one of his earliest and best movies.

But Shyamalan isn’t the only one getting a makeover here. Presumably tired of playing handsome, uncomplicated leading men, McAvoy — a talented Scottish actor best known as the young Professor X in the “X-Men” prequels — has recently expanded his repertoire to include unsavory creeps in films such as “Trance” and “Filth.” Those roles may as well have been practice laps for the Olympic main event that is “Split,” in which his performance is splintered between a gay fashion designer, a renegade nine-year-old, an obsessive-compulsive control freak, and a crazy church lady, among others.

Shyamalan introduces these wildly different personae one at a time, revealing them through the eyes of the movie’s three main characters, a trio of teenage girls taken prisoner from a high school birthday party, who wake up — like the victims in a nightmarish new subgenre of sadism that includes films like “Saw” and “10 Cloverfield Lane” — in a bunker-like cell with only the dimmest clue of the fate that awaits them. Popular above ground, Claire (Haley Lu Richardson) and Marcia (Jessica Sula) are the first to panic, reacting as most audiences probably would in their shoes, while brooding outsider Casey (Anya Taylor-Joy) seems unusually calm … at first, at least.

Trapped underground in an undetermined location (the actual spot is the film’s next-to-last twist), the girls spend several days trying to devise ways to escape. Each attempt will have moviegoers digging their fingernails deeper into their armrests, as McAvoy’s totally unpredictable character manages to gain the upper hand, while the girls try to make sense of the information before them. Meanwhile, to make things a bit easier on the audience, their captor slips out at regular intervals to visit his shrink, Dr. Fletcher (Betty Buckley, the classic “Carrie” actress who also appeared in Shyamalan’s “The Happening”), a sympathetic ear who dispenses exposition by the wheelbarrow.

The more we learn, the scarier McAvoy’s character(s) starts to sound. At the same time, among the would-be victims, only Casey feels fleshed out, as Shyamalan gradually reveals the young lady’s troubled backstory via flashbacks to childhood hunting trips. Taylor-Joy, who recently starred in Robert Eggers’ “The Witch,” has a knack for suggesting dark undercurrents to superficially lovely characters, to the extent that we start to wonder whether McAvoy has meet his match.

Shyamalan’s goal is to keep us guessing, and in that respect, “Split” is a resounding success — even if in others, it could have you rolling your eyes. Still, scaling down to a relatively modest budget and just a handful of locations has forced him to get creative with the script, while a handful of new hires — most notably “It Follows” DP Mike Gioulakis, whose crisp, steady-handed gaze plays against the gritty confusion of the genre — elevate the result in such a way that we’re more inclined to consider the characters’ psychology, even though Shyamalan appears to be making it up to suit his purposes.

Ultimately, “Split” belongs to McAvoy, who has ample scenery to chew, but doesn’t stop there — he practically swallows the camera with his tiger-like teeth. With his head shaved, the actor depends ever so slightly on costume changes (sly contributions from Paco Delgado, who worked on “The Danish Girl”), but otherwise conveys his transformations through body language, facial expression, and accent, as his various selves take “the light” — since, per Fletcher, only one can come out to play at a time. As in “Psycho,” there’s a tendency to over-explain, and while Shyamalan is basically making up rules for dissociative identity disorder as he goes along, the condition has afforded McAvoy the role of his career.