The film portrays two conflicts that take place around Flagstone, a fictional town in the American Old West: a land battle related to construction of a railroad, and a mission of vengeance against a cold-blooded killer. A struggle exists for Sweetwater, a piece of land near Flagstone containing the region's only water source. The land was bought by Brett McBain (Frank Wolff), who foresaw that the railroad would have to pass through that area to provide water for the steam locomotives. When crippled railroad tycoon Morton (Gabriele Ferzetti) learns of this, he sends his hired gun Frank (Henry Fonda) to intimidate McBain to move off the land, but Frank instead kills McBain and his three children, planting evidence to frame the bandit Cheyenne (Jason Robards). It appears the land has no owner; however, a former prostitute (Claudia Cardinale) arrives from New Orleans, revealing she is Jill McBain, Brett's new wife and the owner of the land.
Meanwhile, a mysterious harmonica-playing gunman (Charles Bronson), whom Cheyenne later dubs "Harmonica", pursues Frank. In the film's opening scene, Harmonica kills three men sent by Frank to kill him. In a roadhouse on the way to Sweetwater, he informs Cheyenne that the three gunfighters appeared to be posing as Cheyenne's men.
Back at Sweetwater, construction materials are delivered to build a railroad station and a small town. Harmonica explains that Jill will lose Sweetwater unless the station is built by the time the track's construction crews reach that point, so Cheyenne puts his men to work building it.
Frank turns against Morton, who wanted to make a deal with Jill; Morton's disability makes him unable to fight back. After raping Jill, Frank forces her to sell the property in an auction. He tries to buy the farm cheaply by intimidating the other bidders, but Harmonica arrives, holding Cheyenne at gunpoint, and makes a much higher bid based on his reward money for delivering Cheyenne to the authorities. Harmonica rebuffs an offer by Frank to buy the farm from him for one dollar more than he paid at the auction. As Cheyenne is placed on a train bound for the Yuma prison, two members of his gang purchase one-way tickets for the train, intending to help him escape.
Frank's men betray and ambush him, having been paid by Morton to turn against him, butâmuch to Jill's outrageâHarmonica helps Frank kill them, intending to kill Frank himself. Frank returns to Morton, only to find that he and the rest of Frank's men have been killed in a battle with Cheyenne's gang. Frank then goes to Sweetwater to confront Harmonica. On two occasions, Frank has asked Harmonica who he is, but both times Harmonica refused to answer him. Instead, he mysteriously quoted names of men Frank has murdered. This time, Harmonica says he will reveal who he is "only at the point of dying". The two men position themselves for a duel, at which point Harmonica's motive for revenge is revealed in a flashback:
A younger Frank, already a cruel bandit, is forcing a boy to support on his shoulders his older brother, whose neck is in a noose strung from an arch. As the boy struggles to hold his brother's weight, Frank stuffs a harmonica into the boy's mouth and tells him to play. The brother curses Frank and kicks his brother away, and dies. The boy (Harmonica) collapses onto the ground clutching the harmonica in his mouth.
Harmonica draws first and shoots Frank. As he lies dying, Frank again asks who he is, whereupon the harmonica is placed in Frank's mouth. Frank nods weakly in recognition, collapses to the ground clutching the harmonica in his mouth, and dies. Harmonica and Cheyenne say goodbye to Jill, who is supervising construction of the railway station as the track-laying crews reach Sweetwater. Cheyenne collapses, revealing that he had been fatally shot by Morton during the fight with Frank's gang. The work train arrives, Jill carrying water to the rail workers, while Harmonica rides away with Cheyenne's body.
Who kills McBain and his three children?
Frank