Most of the hundreds of first novels published each year sink like stones into a vast, cold ocean of indifference. A lucky handful receive a more favorable welcome. A.J. Finn’s “The Woman in the Window” is among these fortunate few.

“The Woman in the Window,” by A.J. Finn (William Morrow)

Even before its publication, movie rights were sold as well as foreign rights in multiple countries. Novels such as this, for which publishers have high hopes, are often dreadful potboilers. But if “The Woman in the Window” achieves success, it will be entirely deserved. It’s a beautifully written, brilliantly plotted, richly enjoyable tale of love, loss and madness.

The title character, Anna Fox, is 38 and lives alone in a costly house in uptown Manhattan. We soon learn why she is so often peering out her window. She is agoraphobic and has not left home in nearly a year, but she delights in spying on her neighbors. Otherwise, Anna drinks a great deal of wine, mostly merlot, and watches countless black-and-white movie classics — “Gaslight,” “Rebecca,” “Strangers on a Train” and “Spellbound” are among her favorites.

Anna’s husband has left her and taken their 8-year-old daughter with him. She talks to them by phone and vainly begs him to return. She’s a child psychologist and still advises a few patients by email, but mostly she is alone with her wine, her movies and her cat. She also has a tenant, a handsome carpenter who lives in her basement. His presence injects a bit of “will they or won’t they?” excitement into the story, but mostly she is content to spy on her neighbors.

Then, Ethan Russell, a boy of 16 who lives across the street, arrives bearing a gift from his mother. He is a good-looking, friendly lad: “He looks like a boy I once knew, once kissed — summer camp in Maine, a quarter century ago. I like him.” Anna meets Ethan’s parents, Paul and Jane, and Finn’s plot kicks in.

The Russells are a troubled family. Ethan hints that his father is violent toward his wife and son. Anna uses her binoculars to learn more, and one day sees what she believes is an act of violence. She calls the police, who investigate and find no problem. They think Anna’s wine consumption — two or three bottles a day — along with the many prescription drugs she consumes, have impaired her judgment. (Anna cherishes George Bernard Shaw’s quip that alcohol is the “anesthesia by which we endure the operation of life.”) She continues to spy on the Russells, and dark deeds soon unfold.

As the plot seizes us, the prose caresses us. Anna recalls “Central Park, swans with their ­question-mark necks, high noon beyond the lacy elms.” A woman “walks west, toward the avenue, the crown of her head a halo in the sunset.” Thinking of a man she fears, “I shudder, wade deeper into my wineglass.” She mourns that “yesterday had faded like a flower.” And tells us, “Now the night has my heart in its claws. It’s squeezing. I’ll burst. I’m going to burst.” Anna is a mess, but in her way she’s wonderful.

The author A.J. Finn (A.J. Finn)

Although Finn’s plot must not be revealed, it’s fair to say that his characters are rarely who or what they first appear to be. And that his story ends with a series of mind-boggling surprises. “The Woman in the Window” is first-rate entertainment that is finally a moving portrait of a woman fighting to preserve her sanity.

After finishing the novel, I wanted to know more about the author, A.J. Finn. It turns out Finn is pseudonym of Daniel Mallory, an executive editor with none other than the novel’s publisher, William Morrow. In an autobiographical statement, Mallory writes that he has for years struggled with depression. It is an experience, he writes, that “informs, in part, my debut novel and its traumatized heroine.”

With “The Woman in the Window” he has not only captured, sympathetically, the interior life of a depressed person, but also written a riveting thriller that will keep you guessing to the very last sentence.

Patrick Anderson writes regularly about thrillers and mysteries for The Washington Post.

The Woman in the Window

By A. J. Finn

Morrow. 448 pp. $26.99