A gang of bandits led by Calvera (Eli Wallach) periodically raids a poor Mexican village for food and supplies. After the latest raid, during which Calvera kills a villager, the village leaders decide they have had enough. On the advice of the village elder (Vladimir Sokoloff), they decide to fight back. Taking their few objects of value, three villagers ride to a town just inside the United States border hoping to barter for weapons. They are impressed by Chris Adams (Yul Brynner), a veteran Cajun gunslinger, and approach him for advice. Chris suggests they instead hire gunfighters to defend the village, as “men are cheaper than guns.” At first agreeing only to help them recruit men, Chris eventually decides to lead the group. Despite the meager pay offered, he finds five willing gunmen.
They are the gunfighter Vin Tanner (Steve McQueen), who has gone broke after a round of gambling and resists local efforts to recruit him as a store clerk; Chris’s friend Harry Luck (Brad Dexter), who assumes Chris is hiding a much bigger reward for the work; the Irish Mexican Bernardo O’Reilly (Charles Bronson), who has fallen on hard times; Britt (James Coburn), an expert in both knife and gun who joins purely for the challenge involved; and the dapper, on-the-run gunman Lee (Robert Vaughn), plagued by nightmares of fallen enemies and haunted that he has lost his nerve for battle. On their way to the village they are trailed by the hotheaded Chico (Horst Buchholz), an aspiring gunfighter whose previous attempts to join Chris had been spurned. Impressed by his persistence, Chris invites him into the group.
Arriving at the village, they work with the villagers to build fortifications and train them to defend themselves. They note the lack of women in the village, until Chico stumbles upon Petra (Rosenda Monteros) and discovers the women were hidden in fear that the gunmen will rape them. The gunmen begin to bond with the villagers, and Petra pursues Chico. When Bernardo points out that the gunmen are being given the choice food, the gunmen share it with the village children.
Three of Calvera’s men are dispatched to reconnoiter the village; the seven kill all three. Then Calvera and his bandits arrive in force. The seven and the villagers kill another eight of their cohort in a shootout and run them out of town. The villagers celebrate, believing Calvera will not return. But Chico infiltrates Calvera’s camp and learns that Calvera must return, as his men are short of food.
Some fearful villagers thereupon call for the gunfighters to leave. Even some of the seven waver, but Chris insists that they stay, even threatening to kill anyone who suggests giving up the fight. The seven ride out to make a surprise raid on Calvera’s camp, but find it abandoned. Returning to the village, they are caught by Calvera and his men, who colluded with some of the villagers to sneak in and take control. Calvera spares the seven’s lives, believing they have learned the simple farmers are not worth fighting for, and fearing reprisals from the gunfighters’ “friends” across the border. Preparing to depart, Chris and Vin admit they have become emotionally attached to the village. Bernardo likewise gets angry when the boys he befriended call their parents cowards. Chico declares that he hates the villagers; when Chris points out he grew up as a farmer as well, Chico angrily responds that it is men like Calvera and Chris who made the villagers what they are.
The seven gunmen are escorted some distance from the village, where their weapons are returned to them. They debate their next move and all but Harry, who believes the effort will be futile and suicidal, agree to return and fight.
The gunmen infiltrate the village and a gunfight breaks out. Harry, who has had a change of heart, returns in time to save Chris’s life, but is himself fatally shot. Harry pleads to know what they were fighting for, and Chris lies about a hidden gold mine to let Harry believe he died for a fortune. Lee finds the nerve to burst into a house where several villagers are being held, shooting their captors and releasing the prisoners to join the fight, but is gunned down as he leaves the house. Bernardo, shot protecting the boys he befriended, tells them as he dies to see how bravely their fathers fought. Britt dies after shooting at many bandits but exposing himself from cover. Chris shoots Calvera, who asks him, “You came back… to a place like this? Why? A man like you? Why?” He dies without receiving an answer. The remaining bandits take flight.
The three surviving gunmen ride out of town. As they stop atop a hill overlooking the village, Chico parts company with them, realizing he wants to stay with Petra. Chris and Vin bid farewell to the village elder, who tells them that only the villagers have really won, whereas the gunslingers are “like the wind, blowing over the land and passing on.” As they pass the graves of their fallen comrades, Chris admits, “The Old Man was right. Only the farmers won. We lost. We’ll always lose.