In Texas in 1913, Pike Bishop (William Holden), the leader of a gang of aging outlaws, is seeking retirement with one final score: the robbery of a railroad office containing a cache of silver. They are ambushed by Pike's former partner, Deke Thornton (Robert Ryan), who is leading a posse of bounty hunters hired and deputized by the railroad. A bloody shootout kills several of the gang. Pike uses a serendipitous temperance union parade to shield their getaway, and many citizens are killed in the crossfire.
Pike rides off with Dutch Engstrom (Ernest Borgnine), brothers Lyle (Warren Oates) and Tector Gorch (Ben Johnson) and Angel (Jaime S nchez), the only survivors. They are dismayed when the loot from the robbery turns out to be a decoy: steel washers instead of silver coin. The men reunite with old-timer Freddie Sykes (Edmond O'Brien) and head for Mexico.
Pike's men cross the Rio Grande and take refuge that night in the village where Angel was born. The townsfolk are ruled by Gen. Mapache (Emilio Fern ndez), a corrupt, brutal general in the Mexican Federal Army, who has been ravaging the area's villages to feed his troops, who have been fighting and losing to the forces of revolutionary Pancho Villa. Pike's gang makes contact with the general. A jealous Angel spots Teresa, his former lover, in Mapache's arms and shoots her dead, angering Mapache. Pike defuses the situation and offers to work for Mapache. Their task is to steal a weapons shipment from a U.S. Army train so that Mapache can resupply his troops and appease Col. Mohr (Fernando Wagner), his German military adviser, who wishes to obtain samples of America's armaments. The reward will be a cache of gold coins.
Angel gives up his share of the gold to Pike in return for sending one crate of the stolen rifles and ammunition to a band of rebels opposed to Mapache. The holdup goes largely as planned until Deke's posse turns up on the very train the gang has robbed. The posse chases them to the Mexican border, only to be foiled again as the robbers blow up a trestle spanning the Rio Grande, dumping the entire posse into the river. The pursuers temporarily regroup at a riverside camp and then quickly take off again after the Bunch.
Pike and his men, knowing they risk being double-crossed by Mapache, devise a way of bringing him the stolen weapons including a (anachronistic) Browning M1917 machine gun without him double-crossing them. However, Mapache learns from the mother of Teresa that Angel embezzled a crate of guns and ammo, and reveals this as Angel and Engstrom deliver the last of the weapons. Surrounded by Mapache's army, Angel desperately tries to escape, only to be captured and tortured. Mapache lets Engstrom go, and he returns to rejoin Pike's gang and tell them what happened.
Sykes is wounded by Deke's posse while securing spare horses. The rest of Pike's gang returns to Agua Verde for shelter, where a bacchanal celebrating the weapons transfer has commenced; they see Angel being dragged on the ground by a rope tied behind the general's car. After a brief frolic with prostitutes and a period of reflection, Pike and the gang try to forcibly persuade Mapache to release Angel, barely alive after the torture. The general appears to comply; however, as they watch, the general cuts his throat instead. Pike and the gang angrily gun Mapache down in front of hundreds of his men. For a moment, the federales are so shocked that they fail to return fire, causing Engstrom to laugh in surprise. Pike calmly takes aim at Mohr and kills him, too. This results in a violent, bloody shootout dominated by the machine gun in which Pike and his men are killed, along with many of Mapache's troops and the remaining German adviser.
Deke finally catches up. He allows the remaining members of the posse to take the bullet-riddled bodies of the gang members back and collect the reward, while electing to stay behind, knowing what awaits the posse. After a period, Sykes arrives with a band of the previously seen Mexican rebels, who have killed off what's left of the posse along the way. Sykes asks Deke to come along and join the revolution. Deke smiles and rides off with them.
 
Output: Who is Pike ambushed by on his final score?