The entire plot of "The Good, the Bad and the Ugly" is a series of betrayals and shifting alliances driven by the pursuit of hidden gold. The key pieces of information—the name of the cemetery and the name on the grave—are split between the characters. Tuco knows the cemetery is Sad Hill, while Blondie learns the name on the grave, Arch Stanton, from a dying Bill Carson. This forces them into a reluctant partnership. Angel Eyes, through torture, also learns the name of the cemetery from Tuco.
The climax of the film is the iconic three-way duel, or "Mexican standoff," in the center of Sad Hill Cemetery. Before the duel, Blondie writes the name of the grave on a rock, but this is a bluff. The hidden meaning that becomes clear after the duel is that Blondie was always one step ahead. He had secretly unloaded Tuco's gun the night before, ensuring that Tuco would not be a threat. The duel is therefore between Blondie and Angel Eyes. Blondie shoots and kills Angel Eyes, who falls into an open grave.
The final twist reveals the full extent of Blondie's cynical yet strangely fair code of honor. He does not kill Tuco, but instead forces him into a noose balanced precariously on an unstable grave marker, with his share of the gold at his feet. Blondie then rides off, making Tuco believe he is being abandoned to die. From a great distance, Blondie shoots the rope, freeing Tuco, who is left alive with his half of the money. This final act is a call-back to their earlier partnership of capturing Tuco for bounty and then shooting him free from the gallows, bringing their tumultuous relationship full circle. It perfectly encapsulates the film's theme of ambiguous morality: an act of cruelty and mercy combined.