It's frightening how little we knew about the mentally ill at the end of the 19th century.

“Stonehearst Asylum,” in theaters Oct. 24, uses that medical backdrop for a thriller that teeters on pulp without going over the edge. Ben Kingsley won’t let that happen as the asylum’s superintendent, a man either ahead of his time or with sinister intentions.

Director Brad Anderson (“Transsiberian”) mucks around with therapeutic barbarism and its moral implications, making this “Asylum” a heady place to visit.

 

Jim Sturgess stars as Dr. Edward Newgate, an Oxford alum and the newest member of Stonehearst Asylum’s medical team. Dr. Lamb (Ben Kingsley) applies some unorthodox methods to his patients, some of which Dr. Newgate finds disturbing.

Is something seriously wrong at the asylum, and could the avuncular Dr. Lamb be behind it? And how does the most ravishing mental patient in screen history, played by Kate Beckinsale, factor into Dr. Lamb’s handiwork?

To say more would spoil what Anderson can’t wait to reveal himself, especially when a bedraggled Michael Caine appears early on to spill the story’s beans. The asylum in question appears medieval, and yet some of Dr. Lamb’s methods are remarkably humane. That calls into question modern treatments. Will we look back at 2014 with a similar sense of disdain?

That undercurrent heightens every treatment sequence under Anderson’s supervision.

That late 19th century dichotomy isn’t wasted by a first-rate cast, including Brendan Gleeson in a small but critical role. Sturgess looks out of place initially, with a twitchy affect that draws attention away from co-stars. Soon, his character is forced into heroic situations, and the actor conveys that transformation with care and credibility.

“Stonehearst Asylum” hinges on a meaty twist, the kind doled out in flashbacks and ominous musical cues. It trots out one final “gotcha” in the film’s final moments, a decidedly unnecessary touch. That hiccup isn’t enough to stain a story looking at both our medicinal past and present with unease.

DID YOU KNOW: At the end of the 19th century, doctors believed mental health issues stemmed from problems within the nervous system. They employed hydrotherapy, electrical stimulation and rest to help patients.