“The Discreet Hero” isn’t solely a detective story. As with the cast, the novel has fun reuniting genres we associate with Vargas Llosa. Here are traces of the “total novel” that seeks to represent an entire society, along the lines of “Conversation in the Cathedral,” one of Vargas Llosa’s great masterpieces, an intense, complex, thrillingly alive, darkly political novel of Peru at a time when it didn’t inspire much optimism in anybody. “The Discreet Hero” includes often hilarious echoes of the playful erotic novels — think Gomez and Morticia Addams, but hornier — that featured Don Rigoberto and his second wife, Lucrecia, the sexy stepmother seduced by the demonic, beautiful young Fonchito, Rigoberto’s son from his first marriage. Here too are echoes, though less comic, of the soap opera melodrama of “Aunt Julia and the Scriptwriter.” For most of this novel Vargas Llosa blends these disparate elements skillfully, with his familiar windmilling style. The book is often funny; you turn the pages with relish; it offers up plenty to think about and admire; for most of its length it immerses you in the way you hope any novel will immerse you. Of course a lot of this book’s drive and wonderful verbal energy in English are attributable to what is clearly a superior translation on the part of Edith Grossman, the admired translator of many Spanish-language greats.

Yet as its title implies, “The Discreet Hero” is also a kind of moral fable, suggesting it may have a didactic purpose. It asks what makes for a discreet hero, or for two of them. Felícito is a cholo, raised by his peasant father, spending his whole life “working like a slave, never taking a vacation.” We understand this is a trait we should admire, and of course we do. Felícito also has a nearly mystical side, with a mulatta friend who dispenses ambiguous prophecies that always come true while also signaling looming plot developments. “Human beings, each of us, are chasms filled with shadows,” a priest in the novel remarks, and Felícito certainly has shadows. He has reason to doubt his white-skinned oldest son is really his own. And he regards his dutiful lowborn wife as “a piece of furniture.” Meanwhile he has fallen in love with Mabel, young enough to be his daughter. She’s the kind of prostitute, or semi-prostitute — the distinction matters, in this novel — who “had to feel at least some affection for the man, and also had to get the goods.” Felícito weeps when they finally make love: “Until now I didn’t know what it meant to feel pleasure, I swear.” He buys Mabel a small house and opens a bank account for her.

Felícito refuses the extortionists’ demands and even taunts them with an open letter in the newspaper. He is risking his life. His sons protest they don’t want him to die; they don’t seem to consider that he is placing their own lives in danger too. Felícito tells Mabel: “I’ll never pay an extortionist. Not even if they kill me or the thing I love most in this world, which is you.”

Don Rigoberto likewise stands up to Ismael’s sons, though it threatens “his plans for a joyful retirement rich in material, intellectual and artistic pleasures.” The reader understands that the twins represent one of the most reprehensible phenomena of Latin American culture: privileged white youths who commit as many crimes as they want, shielded by wealth and social position. They are very bad sons, another of the novel’s themes.

“The Discreet Hero” plays out without excessive exploitation of that most annoying feature of crime fiction, the withholding of information. Yet the last third is a disappointment, as Vargas Llosa’s narrative exuberance yields to his didactic intentions. I know we are supposed to admire Felícito for standing up to the extortionists — except I live in a part of the world, Mexico, where people who did that would guarantee their own and probably their loved ones’ violent deaths. How realistic does a novel have to be to resonate realistically outside its setting? Economically and politically, Mexico, along with most of Central America, is not a region that anybody feels optimistic about right now. But nobody goes to a novel for a rebuke of Thomas Piketty’s economic theories. I do wish more of this book had been devoted to the redoubtable Sergeant Lituma. I have a feeling this isn’t his last appearance in a Vargas Llosa novel, and I look forward to his return.