John Larison argues that despite the different tropes they use and the different worlds they occupy, crime and Western stories share many structural similarities:
Both are about the triumph of good over evil. Early in a novel of either genre, we will see our protagonist encounter an injustice, usually the victim of crime (who may or may not still be breathing). Both novels will end when the scales of justice have finally been righted; the perpetrators of evil have met their due punishment. In a crime novel, justice usually comes in the form of a court of law. In the western, justice tends to be delivered by a bullet through the heart.
That’s a good start, but there’s more substance, nuance, and grit in both genres. Crime fiction includes many sub-genres, including cozies (Agatha Christie’s Miss Marple tales) and classic whodunits (Ellery Queen). The reader can settle down with one of these books knowing that justice will inevitably prevail, just like in the Westerns. But then there are hardboiled and noir crime stories. While both feature violence in gritty, naturalistic settings, only hardboiled tales come close to the worldview of classic Western adventures.
In hardboiled crime tales, the protagonist shoots it out with the bad guys to protect the innocent and restore justice. Mickey Spillane’s Mike Hammer is an updated John Wayne battling the bad hombres of New York City. However, in noir tales, traditional justice is just as hard to find as an innocent victim. For example, Raymond Chandler paints a bleak view of human nature in his novels, with both the criminal underworld and the “respectable” upper class up to no good. In such a world, the protagonist has to settle for upholding his personal code of honor, justice for the innocent proving too elusive, if not illusory.
Some of the “crime-westerns” Larison cites in his article certainly don’t end with the good guy riding into the sunset after protecting the righteous and punishing the wicked. Just to name one example, Cormac McCarthy’s “No Country For Old Men” ends with the bad guy, a sociopathic hit man, virtually unscathed and free, leaving behind the corpses of almost all the sympathetic characters. The sheriff who failed to catch the killer or protect the innocent acknowledges his uselessness at the end, and dreads the evil that’s spreading across the land he once loved and knew. Not exactly “Shane.” But, as Larison says, still wildly entertaining.