Raymond Chandler, who knew a thing or two about the fictional detective, famously wrote that he must be “the best man in his world and a good enough man for any world.” Consciously or not, Jason Goodwin has thoroughly absorbed that precept; his own fictional detective, Yashim, might have considered Philip Marlowe a bit uncouth (all that smoking and drinking surely show a lack of self-control), but they are cut from the same cloth when it comes to righting the wrongs of the world.

In “An Evil Eye,” Goodwin’s fourth novel, Yashim’s world is the decaying Ottoman Empire of the early 19th century. The year is 1839, and a new sultan, Abdulmecid, has replaced the old one in Istanbul. In the novel’s most atmospheric, least realized subplot, this change in monarchs occasions a corresponding change in the monarch’s harem. In an echo of Goodwin’s first book, “The Janissary Tree” (2006), the sultan’s harem also contains a mystery that will eventually involve our detective. But in “An Evil Eye,” the more immediate puzzle is posed by a dead body found on the island of Chalki in the well of the monastery. The dead man in the well is marked with a totenkopf — or skull symbol — and when Yashim is dispatched to investigate, it doesn’t take him long to surmise that the dead man might have been Russian.

Goodwin is an author of many strengths — the books in this series can be read independently of each other, and they just keep getting better — and the discovery of a Russian corpse in a Christian well in the heart of a Muslim land allows him to play to the best of those strengths: his remarkable ability to clarify the muddle of that decaying empire. “The Ottomans were not a nation [but] a caste, almost a family,” we learn. “Just as the sultan, as head of the family, maintained his pashas and his odalisques, so the Ottomans maintained their retinues in turn.” Yashim’s effort to restore some semblance of harmony to that family is made all the more complicated by the implication of Fevzi Ahmet Pasha, his old mentor in the service of the former sultan.

The complicated plot that unfolds is deftly controlled throughout, with dangers, chases, intrigues and frequent trips back to the harem. Goodwin’s prose is sharp and surprising (about that dead Russian we’re told, “His skin had wrinkled in the long immersion under water, soft and ridged like the white brains of sheep laid out for sale in the butcher’s market”), and the best part of the entertainment is none other than Yashim, a redoubtable, philosophical hero who finds himself in a dirty, battered world yet still holds out hope: “I think there is always a little gap somewhere, however hard you try to fit everything together. A small space, for something like grace, or mercy.”

There is precious little mercy in the cutthroat world Goodwin portrays here. Yashim is caught between the merciless cunning of his old teacher and the innocence of that teacher’s little daughter, between the politics of the sultanate and the equally twisted politics of the harem. The standout joy of these books is readers’ confidence that we’ve got the right hero, that the calm Yashim will prevail. “In the end,” he tells an exasperated colleague, “it isn’t about people, or sultans, or corruption. It’s about the truth.”

If there were only more such men, Chandler tells us, “the world would be a very safe place to live in.” And maybe the poor old Ottoman Empire would have lasted a bit longer if it had had more Yashims to call upon. As it is, we must hope the original has many, many more adventures.

Donoghue is managing editor of the online magazine Open Letters Monthly.