Mary Deerfield, the main character of Chris Bohjalian’s new novel, “Hour of the Witch,” is a poster child for the proverb, “Marry in haste, repent at leisure.” Having come to Boston as a teenager with her wealthy Puritan parents and lacking sufficiently suitable suitors in this rough, half-civilized place, she marries a well-to-do widower twice her age, one Thomas Deerfield. It doesn’t go well. Deerfield’s courting manners soon vanish, revealing him as mean and petty in speech, given to drink and physically cruel. Worse: He can’t get her pregnant but not for lack of trying.

This is 1662. Plainly, if a married woman isn’t pregnant, she’s barren, and Mary’s feelings of failure don’t help her sex life. She discovers private joy and considers it a gift from God as minor compensation for her marriage, barren of happiness as well as children. Mary finds plenty of material for her nightly fantasies in visions of comely young men she glimpses on the docks or in her father’s office.

If a Puritan woman with a powerful and unashamed sex drive makes you blink, you may want to check your expectations at the door when you open this book. Given the title, the cover design and the time period, readers might assume that the story deals with a presumption of black magic, public suspicions of women as workers of same, and a witch trial. You do get those things — but that’s not all.

Despite her husband’s noticeable flaws, Mary is a dutiful wife and takes pains to hide her bruises. Until the night when her husband, drunk yet again, snatches up one of the newfangled three-tined forks that Mary’s father — a wealthy merchant — has given her and stabs it through her hand. Mary is dutiful, but not a doormat, and shocked and enraged, she makes up her mind to divorce her husband.

Readers always bring themselves to a book. Thus, when reading a historical tale, a shadow of the present always falls upon the past. Our assumptions about morality and behavior swim just under the surface of the reading, and our half-conscious responses to a story set in a time not our own are echoes of what we see as “right.” Historical fiction holds up a mirror to the past; good historical fiction holds up a mirror to the present.

“Hour of the Witch” is very good historical fiction. One of Bohjalian’s great strengths is his research; another is his sense of humanity. By the accretion of lavish detail, he’s able to show us a real world and the people who live in it. He also gives us someone with whom to empathize: Mary is admirable in her determination, independence and clearheadedness. At the same time, she is a person of her own time, and Bohjalian makes clear how the systems of that time work.

We’re subtly brought to understand how a community that hanged a small, female Quaker for the crime of preaching in public also has a judicial system that gives a voice to abused or neglected wives. Divorce wasn’t common in 17th-century Boston, particularly if the complainant was a woman, but it was done.

You might think you know where this is going: Young, intelligent woman who dares to exert her own agency is warned about causing trouble but does it anyway, filled with a sense of her own righteousness. She is, of course, then denounced as a witch and railroaded by malice, ignorance, superstition and the universal tendency of human beings to catch hysteria from one another and tell lies from boredom, self-interest or a desire for importance (see Twitter, any day of the week).

Such things happen; still, it’s not the patriarchal frame-up you might expect. We see, in minute and inexorable detail, just how evidence can be manipulated, ignored, created, and the law itself be traduced. But the tale is told against a solid background of domestic violence, female rivalries and solidarity, and an evenhanded sense of fairness regarding the community in which these events take place. The importance of the religious nature of daily life is woven into the story, not imposed upon it. God and the Devil are real to the Puritans of Boston and the “praying Indians” to whom they’ve spread their faith — sufficiently real that Mary at one point speculates as to the Devil’s gender, concluding (with some cause) that “He most definitely wears breeches. The Devil can only be a man.”

Bohjalian is not only a talented storyteller; he understands women, and it shows in the insightful and empathetic way in which he tells their stories. Historical fiction lives and dies by the details (there is a well-known syndrome among writers called “I’ve done my research and now you’re going to pay . . .”), and while the book is as thick with details as chowder is with clams, the specifics are handled with great skill and delicacy. The book is a thriller in structure, and a real page-turner, the ending both unexpected and satisfying.

Diana Gabaldon is author of the Outlander series. The next installment, “Go Tell the Bees That I Am Gone,” will be published in November.

HOUR OF THE WITCH

By Chris Bohjalian

Doubleday. 416pp. $28.95