Elderly and famous U.S. Senator Ransom "Ranse" Stoddard (James Stewart) and his wife Hallie (Vera Miles) arrive by train in the small western town of Shinbone, to attend the funeral of Tom Doniphon (John Wayne). Prior to the funeral, Hallie goes off with Link Appleyard (Andy Devine) to visit a burned-down house now filled with cactus flowers. She returns so she and Ransom may pay their respects to the dead man at the undertaker's establishment, but the senator is interrupted for a newspaper interview to explain why he would travel so far to pay honor to Doniphon, a common rancher. Stoddard grants the request.
Stoddard's story flashes back to several decades prior when he arrived in Shinbone via a stagecoach, which was robbed by a gang of outlaws led by gunfighter Liberty Valance (Lee Marvin). Stoddard is brutally beaten, left for dead, and later rescued by Doniphon. and nursed back to health by restaurant owner Peter Ericson (John Qualen), his wife Nora (Jeanette Nolan) and daughter Hallie (Vera Miles), who explain to Stoddard that Shinbone's townsfolk are regularly menaced by Valance. Since Link Appleyard (Andy Devine), then the town marshal, proves cowardly and unwilling to enforce the law, Doniphon is the only local courageous enough to challenge Valance's lawless behavior.
Penniless, Stoddard rooms at the Ericson's restaurant and washes dishes. Forced to wait tables on a busy night, Stoddard carries a steak to Doniphon when he is tripped and humiliated by Valance. Doniphon intervenes; Valance stands down and leaves. Force, Doniphan tells the inept Easterner, is the only thing Valance understands, and he needs to either leave the territory or buy a gun. Stoddard maintains he will do neither, explaining he is an advocate for justice and intends to open a law practice. Many in Shinbone believe him crazy, as this makes him a target for Valance, but Stoddard earns the respect and affection of the town when he begins a school for the townspeople with the aid of Hallie, who he discovers cannot read or write and whom he offers to personally teach. Hallie greatly appreciates his help and her role at Stoddard's school.
Secretly, Stoddard tries to teach himself how to shoot a gun. However, Doniphan catches wind of this and takes Stoddard to his house. He shows him an addition he is building on his house in anticipation of marrying Hallie. Doniphon then gives Stoddard a gun lesson to humiliate him by shooting a can of paint which spills on Stoddard's suit. Doniphon warns that Valance will be just as devious. Infuriated by another humiliation, Stoddard punches him in the jaw and leaves.
Shinbone's residents meet to elect two delegates to send to the statehood convention at the territorial capital. Dutton Peabody (Edmond O'Brien), the local newspaper owner, has published a story about local ranch owners' opposition to the territory's potential statehood, and Stoddard claims statehood will ensure solid infrastructure, safety, and education. However, Valance (who is employed by the cattle barons) interrupts the meeting and attempts to bully the townspeople into electing him as a delegate. Despite this, Stoddard and Peabody are elected, prompting Valance to challenge Stoddard to a duel that evening. Doniphon tells Stoddard he should leave town and even offers to have his farmhand Pompey (Woody Strode) escort him. Stoddard stays.
That evening, Valance confronts Peabody for unflatteringly publicizing Valance's defeat in the election. He and his gang destroy Peabody's office and assault him. Seeing that Peabody has been nearly beaten to death, Stoddard goes into the street to face Valance in the duel. In the dark street, Valance toys with Stoddard by firing a bullet into a bucket, drenching Stoddard before Valance disarms him with a shot to the arm. Valance allows Stoddard to bend down and retrieve the gun. Valance then aims to kill Stoddard promising to put the next bullet "right between the eyes," when Stoddard fires and miraculously kills Valance with one shot. Hallie responds with tearful affection. Doniphon congratulates Stoddard on his success but later sees how lovingly Hallie cares for Stoddard's wounds. Sensing that he has lost Hallie's affections, Doniphon gets drunk in the saloon and drives out Valance's gang (Lee Van Cleef and Strother Martin), who have been calling for Stoddard to be lynched for Valance's "murder," after which Pompey drags Doniphon home. There, Doniphon, in a drunken rage, sets fire to his house's addition. Pompey is able to save Doniphon in the blaze, but the house is destroyed.
Subsequently, Stoddard is hailed as "the man who shot Liberty Valance" at the territorial convention for statehood. Called out for his actions by a rival delegate, Stoddard is reluctant to serve based upon his notoriety for killing a man in a gunfight. Seeing Stoddard's shame at this reputation, Doniphon tells Stoddard that he, Doniphon, actually killed Valance from an alley hidden across the street, firing at the same time as Stoddard. Doniphon explains that he knew Hallie's affections belonged to Stoddard and shot Valance to secure her happiness. Knowing this, Stoddard returns to the convention.
The flashback ends and the now aging Stoddard informs his interviewers that he was then elected to Congress, married Hallie, and served terms as Governor, U.S. Senator, Ambassador to Great Britain and again in the Senate. The newspaper man, understanding the truth about Liberty Valance's death, burns his notes and says to Stoddard, "This is the West, sir. When the legend becomes fact, print the legend". Stoddard and Hallie then board the train for Washington, where he informs Hallie, to her delight, that he plans to retire from politics and return to the territory to set up a law practice. When Stoddard thanks the train conductor for the many courtesies extended to him by the railroad, the conductor says, "Nothing's too good for the man who shot Liberty Valance!" The words beleaguer Stoddard, and as the train moves along, he and Hallie stare off into the distance.