In the American Old West of 1874, construction on a new railroad led by Lyle (Burton Gilliam) runs into quicksand. The route has to be changed, which will require it to go through Rock Ridge, a frontier town where everyone has the last name of "Johnson" (including a "Howard Johnson," a "Dr. Samuel Johnson," a "Van Johnson" and an "Olson N. Johnson"). The conniving State Attorney General Hedley Lamarr (Harvey Korman) wants to buy the land along the new railroad route cheaply by driving out the townspeople. He sends a gang of thugs, led by his flunky assistant Taggart (Slim Pickens), to scare them away, prompting the townsfolk to demand that Governor William J. Le Petomane (Mel Brooks) appoint a new sheriff. Lamarr persuades the dim-witted Le Petomane to select Bart (Cleavon Little), a black railroad worker who was about to be hanged, as he believes a black lawman will so offend the townspeople that they will either abandon Rock Ridge or lynch the new sheriff, with either result paving the way for him to take over the town.
With his quick wits and the assistance of drunken gunslinger Jim (Gene Wilder), also known as "The Waco Kid" ("I must have killed more men than Cecil B. DeMille"),[4] Bart works to overcome the townsfolk's hostile reception. He defeats and befriends Mongo (Alex Karras), an immensely strong, slow-thinking (but surprisingly philosophical) henchman sent by Taggart and Lyle to kill Bart, and then beats German seductress-for-hire Lili von Shtupp (Madeline Kahn) at her own game. Lamarr is furious that his plans keep failing and decides to destroy Rock Ridge with a newly recruited and diverse army of thugs, including western outlaws, Klansmen, Nazi soldiers, outlaw bikers and other stereotypical "bad guys".
Bart gathers the town, along with the railroad workers, three miles east of Rock Ridge to build a fake town as a diversion. The workers labor all night to build a perfect replica, but with no people in it Bart realises it won't fool Lamarr's villains. Ordering the townspeople to make "exact replicas of themselves," Bart leaves with Jim and Mongo to construct a tollbooth. When they raiding party arrives at the booth, Taggart is forced to send someone back to "Get a shitload of dimes", as the villains have neither the change to go through it, nor enough common sense to simply ride around it.
Once through the tollbooth, Lamarr's villains attack the fake town populated with dummies, which Bart boobytrapped with several dynamite bombs. Bart tries setting off the bombs but is unsuccessful as the detonator does not work. Jim is given the task of exploding the bombs, and fires his pistol at them. After the bombs explode, launching villains skyward, the Rock Ridgers attack the villains.
The resulting fight between the townsfolk and Lamarr's army of thugs breaks the fourth wall, literally. The fight spills out from the Warner Bros. film lot into a neighboring musical set being directed by Buddy Bizarre (Dom DeLuise), then into the studio commissary, and ultimately into the surrounding streets (specifically, Olive Avenue in Burbank). The citizens chase the villains back to Rock Ridge to destroy them, but Lamarr takes a taxi ". . . off this picture." He arrives at Grauman's Chinese Theatre to watch the "premiere" of Blazing Saddles. Unfortunately, he sees on the movie screen that Bart has arrived outside the theatre. Bart ends up killing Lamarr by shooting him in the groin. Bart and Jim then go into the theatre to watch the end of the film, where Bart decides to leave Rock Ridge, much to the sadness of the townspeople and the railroad workers, for his work there is done. As he rides off, he finds Jim (who still has the popcorn that he bought at the theatre), and the two decide to go off to "nowhere special." They ride a short distance out of town, hand their horses off to the movie's wranglers and are driven away in a Cadillac limousine into the sunset.