Diabolical, coldblooded, racist, horrifying. Not the sort of qualities you associate with Sir Patrick Stewart, a global darling for his wise, kindly roles in “Star Trek” and “X-Men.”

But being cast against type is just what he wanted when he signed on as the clever, regal villain of writer/director Jeremy Saulnier’s punishing thriller “Green Room.” A thinking person’s fright film, it caused quite a stir at the Cannes and Sundance film festivals. It opens locally Friday with a cautionary R rating “for strong brutal graphic violence, gory images, language and drug content.”

The setup is simple: A punk band playing at a rural white supremacist roadhouse witnesses a homicide. Outnumbered by violent neo-Nazis whose Gruppenführer is none other than Stewart, the musicians try to survive with a few unlikely allies. While the movie is twisted and traumatic, it is also subtle, smart and thought-provoking.

The star and director spoke by phone to explain why they chose to make an ultrarealistic survival film rather than safer studio fare.

After playing Capt. Jean-Luc Picard and Prof. Charles Xavier for established filmmakers, Stewart said, it was natural to want to work with an independent newcomer as a depraved monster.

“It’s been a little frustrating because diversity has been a keynote of my career for 56 years,” Stewart said. “Characters like this have been many in my career,” including Shakespearean roles such as Othello, Richard III and Hamlet.

“Only a couple of years ago I was in one of the nastiest, ugliest, bloodiest productions of ‘Macbeth’ you could ever hope to see,” he said with pride.

The character he plays in the new film is not a screaming racist demagogue but a soft-spoken gentleman who is a father figure to his young blackshirts, sending them off to massacre the group’s enemies with supportive encouragement. By stripping away the anti-intellectualism of typical fascist portraits, the part reveals the dark underlying appeal of hate and intolerance.

“Violence is a fascinating subject,” Stewart said. “It has historically always appealed to actors because we get to explore it in a relatively safe environment.”

Saulnier said he was drawn to “Green Room” because it’s high-stakes filmmaking.

“I was first introduced to cinema by my cousins making me see really gory scenes from ‘Dawn of the Dead’ or the ‘Friday the 13th’ franchise,” he said. “It was a wonderful experience to be so terrified and so fascinated while I was safe in the basement of the house.”

He grew up loving Monty Python films because they were violent and funny. “Now I’m making these films to do what psychologists call ‘coping with my trauma,’ ” he said, adding a level of emotional responsibility to bloody stories. His goal is to deliver surprise without throwing away the logic, as many genre films do.

“It takes a lot of work, but even more important, less interference,” he said. “I’d definitely like to make the jump” to big-budget studio fare, except that he calls most commercial films something the keeper of a horse stable has to sweep up.

“I want a pension and health care,” Saulnier said. “But the real feat is exposing yourself to the committee prematurely. I hate the idea of going through draft after draft” like a number of in-demand indie filmmakers have had to do after signing on to execute studio-controlled movies. “Rather than carefully choreographed moments, I want to feel something. I want the heart to beat faster.”

As did his image-transforming cast.

“I just cast people who weren’t used to being in action flicks. The young kids [including Anton Yelchin, who plays Chekov in the new ‘Star Trek’ films; ingénue Imogen Poots, and comedy regular Alia Shawkat] just leapt on these parts. Imogen doesn’t get to do this very often. She had a ball. She got real feral.” Each brought “a level of performance and grounding and realism which I think heightens the impact of the entire movie.”

When it comes to the dark material, Stewart was just as excited as the younger cast.

“Very early on, I was impressed with a conversation I had with the director, when Jeremy talked about the tonality of the character being very muted and quite low-key and reasonable,” Stewart said. “I was intrigued by that, the idea that there could be a way of taking on this person that would be unexpected.”

Even with that vote of confidence, Saulnier said he’s not ready to go to the big leagues. “I’d rather write from the gut level than play to certain standards. I want sloppy and real and unpredictable.”

Having opened a snake pit with this film, it’ll be interesting to see what can of worms, hornet’s nest and Pandora’s box he unlocks next.