The movie is nominally a western (and apparently the highest grossing Western ever, would you believe.
Hedley Lamarr ("..That’s Hedley" – a joke that many of us younger folks won’t understand anymore – apparently, there used to be a silent film star (female) called Heddy Lamarr. She sued. Mel Brooks settled out of court), the State Procurer/Attorney General/Assistant to the Governor, played by Harvey Korman, is keen to build a railroad. The problem is, he wants to build it through the town of Rock Ridge (entirely populated by people who’s last name is Johnson. There’s even a Howard). Needless to say, the townspeople, who all own their own land, would, at the least object, and if not, demand large amounts of money for their land.
A dastardly scheme is dreamt up in order to scare the townspeople away. The townspeople complain to (the rather simple) Governor William J. LePetomane (Mel Brooks), asking for a sheriff to protect them. Lamarr figures that the best way to solve THAT problem is to hire a sheriff that the townspeople wouldn’t accept for, well, all the tea in China. He’s black, played by Cleavon Little.
Bart (for that is the sheriff’s name) has a difficult start in Rock Ridge. Fortunately, he is befriended by Jim, the Waco Kid (Gene Wilder). Between them, they set out to save the town of Rock Ridge, despite the obstacles placed in the way by Lamarr and his cronies.
That is, really, the plot in a nutshell. Everything does come right in the end, with Bart and Jim riding (then subsequently driving) into the sunset.