Robert Eggers’s debut film, The Witch, is made with all the assuredness of one who’s a veteran master of horror. Set in Puritan New England on the edge of civilization, it builds tension through a mix of period detail and supernatural bumps in the night, telling the story of a teenage girl, Thomasin (Anya Taylor-Joy), and her family as they’re tormented by a supernatural presence in the woods. The Witch has been hailed by critics since its release last week, though the film’s scare factor has been much debated. But it’s the ending, particularly the resolution of Thomasin’s story, that distinguishes it from most traditional chillers, blending horror with an odd note of empowerment (spoilers ahead).

Throughout the film, Thomasin’s family is picked off one by one until she’s the only one left (a particularly gory moment near the end sees her father William gored by the horns of a demonic goat named Black Phillip). She then signs herself over to the devil and joins a coven of witches dancing in the woods; the film closes on Thomasin levitating and laughing with delight. In an interview, Eggers said he didn’t initially approach his screenplay of The Witch as Thomasin’s story, but that he eventually realized she had to be the heart of the film.

The original draft was about how the titular witch manifested herself to different members of the family, meaning the film spent roughly equal time with everyone. “But through working on the second draft with my producers, Thomasin became the protagonist,” he said, adding that the film still works as an ensemble piece. In the story, the witch and her demonic partners take several forms: a goat, a raven, a rabbit, a beautiful woman, and a disfigured crone. While most of the other family members are besieged by these figures, Thomasin is targeted instead with suspicion from her parents and siblings, who come to think she’s in league with evil forces. “It was not my intention to make a story of female empowerment,” Egger said, “but I discovered in the writing that if you’re making a witch story, these are the issues that rise to the top.”

The director grew up in a rural New England town and was fascinated with the history of the witch-trial era from a young age. “I wanted to make an archetypal New England horror story, something that would feel like an inherited nightmare, a Puritan nightmare from the past,” he said. The film is, after all, subtitled A New England Folk-Tale, and seems to serve as an eerie warning from the era against being prideful and leaving the community, which is William’s original sin. “The Puritans believed that if you were part of ‘the elect,’ you could not be harmed by witchcraft,” Eggers said.

He tried to build The Witch around the Puritans’ psychology. A folk tale like this one wouldn’t have been seen during that time as an allegory, or a story told for broader social reasons. “It wouldn’t have been a yarn to keep people under control, just like the Ten Commandments wasn’t just a yarn to keep people under control,” he said. “All of this is ‘literal truth’ in the period.”

The Witch really does feel like it’s coming out of the past—much of the dialogue is lifted from historical record—and its characters approach the horrors of the woods in a period-appropriate way. Talk of witches isn’t mumbo-jumbo to be dismissed, but a very real fear associated with shame and guilt. “In these people’s minds, there’s no question of the supernatural,” Eggers said. “When William is upset about Katherine bringing up the idea of a witch, it’s less that he doesn’t believe a witch is possible, and more that his pride has been hurt.”

The film’s exploration of patriarchal power was the key to unlocking Thomasin’s story. As a woman in the 17th century, she’s entirely stripped of agency. She exists only to work and help her family, and eventually be married off and bear more children. As The Witch progresses, it becomes clear that the campaign being waged against her family is targeted at freeing her so that she can join the coven in the woods. The idea that she’s been liberated is an intentionally muddy one—when she submits to Satan near the end of the film, he takes the form of a man—but there’s a giddy sense nonetheless that she has triumphed.

When asked about The Witch’s deeper commentary at a press conference, the actress Anya Taylor-Joy said she thought the film had a “happy” ending—because joining the coven is the first choice Thomasin gets to make on her own. Eggers is careful to communicate the darkness of Thomasin’s coercion, but doesn’t shy away from the fact that she’s leaving a repressive society behind. When he started thinking about The Witch, his focus was on the unknown, on “understanding where all this stuff comes from, the origins of the clichés—how they’re powerful, how they’re part of everyday life.” But he’s surprised and happy with the way his story evolved, and how it can speak to important modern issues despite being set centuries ago. Thomasin and The Witch seem destined to enter the great canon of horror films that includes the likes of Carrie, The Descent, and A Nightmare on Elm Street: stories that terrify by tapping into the immense power and fury of isolated women.