The town of Vinegaroon, TX, is the home to Judge Roy Bean (Walter Brennan), who calls himself "The Only Law West of the Pecos." Bean keeps a saloon, where he also conducts trials, using his office to get fat on fines and the seizure of property, and hanging most of those who get in his way, sometimes more than one a day. Cole Hardin (Gary Cooper) is a saddle-tramp brought in on a charge of stealing a horse belonging to Bean's chief stooge, Chickenfoot (Paul Hurst). Hardin's conviction by a jury made up of Bean's hangers-on (with the undertaker, played with low-key comic zeal by Charles Halton, waiting eagerly for the verdict and the hanging) seems certain, despite his contention that he bought the horse from another man, until Hardin recognizes the judge's obsession with the English actress Lily Langtry. Hardin feigns having seen, met, and known Miss Langtry intimately, and he cons the judge into delaying the death sentence until Hardin can send for a lock of the actress' hair that he supposedly has in El Paso -- that's long enough for the real horse thief (Tom Tyler) to show up and get killed.
By the time the dust settles, the judge, for all of his warped sense of justice and corrupt nature, finds himself genuinely liking Hardin as something of a kindred spirit, as bold and daring as he was in his youth, and feeling something like friendship for him. But Bean also tries to shoot Hardin when he decides to cast his lot with the homesteaders, led by Jane-Ellen Mathews (Doris Davenport) and her father, Caliphet (Fred Stone), who have been fighting for survival against Bean and his cattle-rancher allies every step of the way. Hardin tries to appeal to the better nature within the judge, and also saves him from an attempted lynching, but when that fails, and a corn crop is burned and Mr. Mathews killed, he sees no choice but to take action. He gets an arrest warrant sworn out and is deputized by the county sheriff. Taking Bean in his saloon or anywhere in his town (renamed Langtry by the judge, in honor of the actress) is impossible, but then it's announced that Lily Langtry will be appearing in Texas, a long day's ride away from Bean's stronghold. The judge, dressed in his full Civil War regalia and with his men in tow, rides to see the performance while Hardin gets ready to try and arrest him. The kind of climactic shoot-out that follows has been done to death in the decades since, but it was something new and revelatory in a Western in 1940, and still plays beautifully on a dramatic level, capturing in full the complexity of the relationship between these two antagonists.