In 1882, the town of Vinegaroon, Texas, is run by Judge Roy Bean, who calls himself "the only law west of the Pecos." Conducting his "trials" from his saloon, Bean makes a nice corrupt living collecting fines and seizing property unlawfully. Those who stand up to him are usually hanged—given what Bean calls "suspended sentences". Cole Harden is a drifter brought in on a charge of stealing a horse belonging to Bean's main sidekick, Chickenfoot. Harden's conviction by a jury composed of Bean's hangers-on seems certain; even the undertaker waits eagerly for the verdict and subsequent hanging. Bean dismisses Harden's contention that he bought the horse legally from another man. Noticing the judge's obsession with the English actress Lily Langtry, Harden claims to have met Miss Langtry, spoken with her, and to have known her intimately. He cons the judge into delaying the death sentence until Harden can send for a lock of the actress' hair, which he supposedly has in El Paso. The delay is long enough for the real horse thief to show up and get killed. Despite his warped sense of justice and corrupt nature, Bean genuinely likes Harden, considering him something of a kindred spirit. Harden is as bold and daring as Bean was in his youth, and the judge feels something like friendship for him, but this "friendship" does not stop Bean from trying to shoot Harden when the drifter lends his support to the homesteaders—a group led by Jane-Ellen Mathews and her father Caliphet. The struggling homesteaders have been at odds with Bean and his cattle-rancher allies for a long time. Harden tries to appeal to the judge's better nature. He even saves Bean from an attempted lynching. When that fails, and a corn crop is burned, and Mr. Mathews killed, Harden sees no choice but to take action. He gets himself deputized by the county sheriff and swears out an arrest warrant against Bean. Arresting Bean in Vinegaroon—now renamed "Langtry" by the judge in honor of the actress—is impossible with all of Bean's men around. When Bean learns that Lily Langtry will be appearing in a nearby town, a long day's ride from Vinegaroon, he has one of his men buy up all the tickets. Bean dons his full Confederate Civil War regalia and rides to see the performance with some of his men as an "honor guard". He enters the theater alone to await the performance, leaving his henchmen outside. Unknown to Bean, Harden has been waiting in the theater to arrest the judge. A standoff and shoot-out occur, and Bean is fatally wounded during the gunfight. Harden carries his dying friend backstage to meet the woman he has adored for so long. As Bean stares at the "Jersey Lily", he dies. Flash forward to two years later, Harden and Jane, now married and having rebuilt the burned farm, watch as new settlers arrive to the territory.
When Gary Cooper learned that Walter Brennan would be playing the part of Judge Roy Bean, he tried to back out of the film, believing his character would be reduced to a relatively minor role. Although Goldwyn assured Cooper that his role would be expanded, Cooper remained unconvinced, writing to Samuel Goldwyn, "I couldn't see that it needed Gary Cooper for the part." Goldwyn remained adamant, though, about Cooper's contractual obligations and insisted that he star in the film. In a formal letter to Goldwyn indicating his intention to sever their future working relationship, Cooper agreed to fulfill his contract and to "perform my services... to the fullest of my ability, with the express understanding that I am doing so under protest." Cooper and Brennan made such an effective team that they did a total of six films together: The Cowboy and the Lady, The Westerner, Meet John Doe, Sergeant York, Pride of the Yankees, and Task Force. In addition to the previously mentioned six films, Brennan and Cooper also appeared in The Wedding Night and Watch Your Wife for a total of eight films made together.