Plot
On the American frontier of 1874, a new railroad under construction will have to be rerouted through the town of Rock Ridge to avoid quicksand. Realizing this will make Rock Ridge worth millions, territorial attorney general Hedley Lamarr plans to force Rock Ridge's residents out of the town and sends a gang of thugs led by his henchman Taggart to shoot the sheriff and trash the town.
Not wanting to go with Reverend Johnson's suggestion to leave, the other prominent citizens named Johnson lead the other townspeople in demanding that Governor William J. Le Petomane appoint a new sheriff to protect them. Lamarr persuades dim-witted Le Petomane to appoint Bart, a black railroad worker about to be executed for assaulting Taggart. A black sheriff, Lamarr reasons, will offend the townspeople, create chaos and leave Rock Ridge at his mercy.
After an initial hostile reception in which he takes himself hostage to escape, Bart relies on his quick wits and the assistance of Jim, an alcoholic gunslinger known as the "Waco Kid", to overcome the townspeople's hostility. Bart subdues Mongo, an immensely strong and dim-witted, yet philosophical henchman sent to kill him, then outwits German seductress-for-hire Lili Von Shtupp at her own game, with Lili falling in love with him.
Upon release, Mongo vaguely informs Bart of Lamarr's connection to the railroad, so Bart and Jim visit the railroad worksite and discover from Bart's best friend Charlie that the railway is planned to go through Rock Ridge. Taggart and his men arrive to kill Bart, but Jim outshoots them and forces their retreat. Furious that his schemes have backfired, Lamarr has Taggart put out an ad for the enlistment of every criminal in the West. Answering the ad are a group of common criminals, motorcycle gangsters, Middle-eastern brigands mounted on dromedaries, Nazi soldiers, and Ku Klux Klansmen.
East of Rock Ridge, Bart introduces the White townspeople to the Black, Chinese, and Irish railroad workers who have all agreed to help them in exchange for acceptance by the community, and explains his plan to defeat Lamarr's army. They labor all night to build a perfect copy of the town and its inhabitants as a diversion.
Bart, Jim, and Mongo buy time by constructing a fake tollbooth in the raiders' path, forcing them to send for change to pay the toll. Once through the booth, the raiders attack the fake town, which has been booby trapped with dynamite. After Jim detonates the explosives with his sharpshooting, launching the attackers skyward, the townspeople and workers attack the raiders.
The resulting brawl between townspeople, railroad workers, and Lamarr's thugs literally breaks the fourth wall and bursts onto a neighboring movie set where director Buddy Bizarre is filming a Busby Berkeley-style top-hat-and-tails musical number. The melee then extends into the studio commissary for a food fight and spills out of the Warner Bros. film lot onto the streets of Burbank, California.
Lamarr escapes the brawl and hails a taxi, instructing the cabbie, "Drive me off this picture!" He hides at Mann's Chinese Theatre, which is showing the premiere of Blazing Saddles. As he settles into his seat, he sees onscreen Bart arriving on horseback outside the theatre. Bart blocks Lamarr's escape and shoots him in the groin. Bart and Jim then enter the theater to watch the end of the film.
Back in the film, Bart announces to the townspeople that he is moving on because his work is done and he has grown bored with protecting them. Riding out of town, he finds Jim, still eating his popcorn, and invites him along to "nowhere special". The two friends briefly ride into the desert before dismounting and boarding a limousine which drives off into the sunset.