A notorious 1971 psychological experiment is the subject of Kyle Patrick Alvarez’s docudrama, in which some excellent young actors play students hired to pretend to be prisoners and guards in a poorly-managed academic exercise that goes wildly off the rails. Despite its intriguing premise and strong performances, the picture grows increasingly unhinged, too. Of course to a certain extent that derives from the director’s desire to use his style to mirror the actual events, but it makes for an uneven, though compelling and unsettling film.

The initiator and general overseer of the experiment was Dr. Philip Zimbardo, played here by Billy Crudup, whose book “The Lucifer Effect” served as the basis for Tim Talbott’s script. Zimbardo appears to have been a confident fellow who grew increasingly uncertain about the methodology he’d developed as the project went on. He and his coterie of grad students selected eighteen male students from among those who’d volunteered for the experiment at the then-considerable promise of $15 a day over the course of two weeks. Though most said that they’d prefer to play prisoners, those who got their wish certainly regretted the choice before long.

The back-stories of the participants are pretty much ignored: Alvarez does show one of them, Daniel Culp (Ezra Miller), being “arrested” in front of his protesting son, but that’s just a brief moment before he’s been transformed into a prisoner sharing a “cell”—a classroom—with others in the basement hallway of the Stanford building Zimbardo has commandeered. He and his fellow prisoners initially treat what they’re undergoing as a lark—after all, the participants who have been named guards are prohibited from any sort of physical abuse. But that soon changes as the guards show a more and more sadistic streak, demanding silence and complete obedience, banging their nightsticks on the walls and doors, calling for checks in the middle of the night, and in extreme cases putting recalcitrant prisoners into a closet that serves as a solitary confinement cell.

The most vitriolic of the guards is Christopher Archer (Michael Angarano), who adopts the persona of a particularly nasty keeper who tormented Paul Newman in “Cool Hand Luke.” As time goes on he devises more and more unpleasant means of humiliating the prisoners, and the other guards follow his lead. Some of the prisoners—Culp and Peter Mitchell (Tye Sheridan) most notably—protest, but their resistance merely brings increased mistreatment, and it doesn’t take long for their cellmates to become totally cowed and cravenly obey their keepers, undercutting any sense of solidarity that might have initially existed. Both “rebels” ultimately break under the pressure within days, begging the “parole board” headed by Zimbardo for relief or release. Giving in to their pleas is stoutly resisted, however, by Jesse Fletcher (Nelsan Ellis), an ex-con the professor has added to his staff in order to maintain the authenticity of the experiment.

As things grow worse, Zimbardo will be forced to make some adjustments, especially regarding Culp, but after the grad assistants have abandoned ship, his own girlfriend (Olivia Thirlby) has raised questions about the direction things have taken and even Fletcher has decided that things have gone too far, Zimbardo insists on pressing on. Presumably the urge to complete a complicated experiment is driving him, but one gets the feeling that he’s getting a little sadistic himself—barking out a sharp rebuke, for example, to a colleague who wanders into the building and questions the procedure the not-so-good doctor has established for the project. Eventually, however, as matters seem to be reaching a dangerous point, Zimbardo calls the experiment off, though it has over a week to go. A postscript shows the students arguing with one another about what had happened in later interviews, some like Archer rather blasé in protesting that he was only playing a part and others like Culp contending that if he’d been a guard he wouldn’t have gone so far.

As a psychological study, Zimbardo’s work showed how quickly and easily guards can become abusive toward prisoners even when the situation is merely simulated. (Indeed, Zimbardo is hailed for his groundbreaking work in the closing credits.) From today’s perspective, however, it seems clear that the project wasn’t especially well-designed even for its time, and one of the most notable things is that the aftermath was so mild: Zimbardo didn’t lose his job and apparently wasn’t even disciplined, and none of the participants sought any legal redress for what they suffered. One can only image the outcry that would occur if anything similar happened now.

Setting aside such considerations, however, Alvarez’s film certainly reeks of verisimilitude, not only in terms of the period detail (those clothes! that facial hair!) but in the claustrophobic setting (Gary Barbosa was production designer, Andres Cubillan the art director, and Sandra Skora the set decorator). Jas Shelton’s camerawork has a gritty, haphazard look that suits the material, and Fernando Collins’ editing brings visceral energy to the interaction among the students. The performances by the young actors are excellent across the board, with Miller and Angarano the standouts. Oddly enough, it’s Crudup who comes off a trifle stiff in their company, though he does capture Zimbardo’s unraveling toward the close convincingly.

In the final analysis “The Stanford Prison Experience” turns out to be an endurance test for viewers, just as it was for at least some of the participants. That’s Alvarez’s point, of course: when it’s over you may think you’ve been through the wringer, too.