So you have a pair of bosses in one realm. They're both corrupt, and they both sell a certain type of goods (e.g. guns, alcoholic beverages, fabrics, etc.). The town they run is a virtual ghost town. Then a lone warrior (usually a stranger) shows up, usually unprepared, and after learning about the situation in the town, he decides to eliminate both bosses and free the realm from their grip. This involves an elaborate spy game in which he masquerades as a member of one boss's gang and works behind the scenes to ensure that both gangs are completely annihilated.
Sometimes, there'll be a Distressed Damsel held prisoner (often due to a gambling debt) by the gang of which the lone warrior is a member. If that's the case, he'll eventually free her and send her (and, if present, her family) away with some money.
Note that for a conflict to qualify as this, the conflict already has to be underway by the time the lone warrior shows up. If he's the one who started the conflict in the first place, you may be looking for Playing Both Sides, of which it's a Sub-Trope.
Also a subtrope of Whole Plot Reference, in this case to A Fistful of Dollars, although this plot actually predates the film.
Compare Double Agent (who's usually genuinely on one side). If this is presented as an option in a videogame, it may be an example of Omnicidal Neutral.
Hokuto No Ken had one such episode where two rival gangs are laying waste to the town. Ken's actions finally end in the two gang leaders unwillingly crushing each other to death via Pressure Point-enhanced Bear Hug. Ken has a rare Bond One-Liner at this point, saying they make a lovely couple.
Subverted in Samurai Champloo and Kazemakase Tsukikage Ran. Both have a basically Jidai Geki setting, and both also have episodes that seem to be shout outs, having the ronin protagonists come to a town occupied by rival gangs. However, in both works, one of the gangs is clearly the good guys (probably owing to the fact that in Yojimbo one was A Lighter Shade of Black), and the protagonist(s) takes their side.
Kaze No Yojimbo: George Kodama arrives into a town divided by two rival syndicates and tracks. He's searching for a man called Araki Genzo and what happened to a missing railcar, and end up playing them.
Daredevil does this from time to time with the identity of a mysterious mob enforcer called "shades".
Batman had an emergency plan to start a Gang War as Matches Malone and secretly manipulate it so as few people died as possible. Unfortunately, Stephanie Brown didn't realize Matches' key role in the plan when she set it in motion.
The Punisher has been known to do this when his usual methods are too direct. Although at least once he did the opposite and secretly facilitated a massive peace conglomeration among mob families so the leaders would all eventually meet to negotiate and he could get them all at once in the same room.
Last Man Standing, set during the Prohibition era. Unlike Fistful of Dollars, this one is an authorized remake of Yojimbo.
Roadhouse Nights is a loose adaptation of Red Harvest from Paramount Pictures, coincidentally the same studio that adapted The Glass Key.
Support Your Local Gunfighter, starring James Garner, is a parody about a gambler named Latigo who wanders into a jerkwater mining town led by, you guessed it, two mining bosses looking for gold. He pretends to be an enforcer for both sides. Hilarity Ensues.
Millers Crossing, which is inspired chiefly by The Glass Key and is about a gang war that starts when one boss puts a bookie (who the other boss had put a hit on) under his protection, with The Dragon to the first boss (who, unusually for this trope, survives) Playing Both Sides.
Sukiyaki Western Django is about a lone gunman who joins forces with a prostitute to take down the Genji and Heike gangs a few hundred years after the Genpei War. Bonus points for including a character called Piripero (the name of the cooper in Fistful of Dollars).
Pretty much Shintaro Katsu's Zatoichi had this as his M.O. whenever he walked into a town with two oyabuns/gangs/corrupt officials. You could bet that by the end of the episode or movie they'd all be dead after Zatoichi had been playing them or they'd played him for a fool and the blind anma had exacted bloody vengeance on them and their underlings.
Jhegaala was referred to in one review as "Steven Brust doing Red Harvest". The critic would be pretty much accurate in his assessment. The plot involves ex-assassin Vlad Taltos returning to his hometown and finding it wracked with corruption and caught between a corrupt merchants guild and a "guild" of witches. Vlad naturally plays the two against each other.
Another potential subversion: Red Country (a fantasy Western) has the protagonists go to a "town" that is being fought over by two rival saloon owners/brothel keepers and they fight on the side of the one that they interpret (possibly incorrectly) as the good guy.
At least one killer in NUMB3RS, particularly one who caused domino-effect killings (he shoots at Gang A, who retaliates against Gang B, who retaliates back, people get caught in the crossfire... repeat until about 150 people are dead) after his young son was murdered by gangsters. By the time the crew catches up with him, he is very clearly insane.
The Second Doctor Doctor Who story "The Highlanders", in which the Doctor accidentally gets caught up in war between the Jacobites and the English, poses as a German and has a lovely time playing both sides off against each other by selling them fabricated information.
In the original Knights of the Old Republic, when you arrive to the Sith Academy world Korriban, you find yourself drawn into a power play between two top instructors, vying for control over the Academy. While you can support either of them, the most satisfying resolution is to let them both think of yourself as their double agent and ultimately triple-cross them into destroying each other.
Parodied/subverted in the The Order of the Stick bonus strip "Uncivil Servant", which shows an incident from the backstory of Heroic Comedic Sociopath and Token Evil Teammate Belkar Bitterleaf. Belkar arrives in a town and sees men from two rival organizations demanding money from a shopkeeper. Both of them see Belkar slay a giant bug and each wants them on their side, because of his skills. Belkar ends up killing them both, and does a Shout-Out to Toshiro Mifune as he does so. However, in a darkly humorous Tomato Surprise, it turns out that Belkar misread the situation and killed innocent people — the two guys weren't gangsters, but a policeman and a fireman each seeking donations for their organizations. The two organizations also have a volleyball game for charity coming up, and each wanted Belkar because of his jumping skills.