He was nominated for a Golden Globe for his performance as the wizardly title character in “Willy Wonka and the Chocolate Factory” (1971). The film was a box-office disappointment, partly because of parental concern that the moral of Roald Dahl’s story — that greedy, gluttonous children should not go unpunished — was too dark in the telling. But it went on to gain a devoted following, and Willy Wonka remains one of the roles with which Mr. Wilder is most closely identified.

His next role was more adult but equally strange: an otherwise normal doctor who falls in love with a sheep named Daisy in a segment of Woody Allen’s “Everything You Always Wanted to Know About Sex but Were Afraid to Ask,” in 1972. Two years later, he reunited with Mr. Brooks for perhaps the two best-known entries in either man’s filmography.

In “Blazing Saddles,” a raunchy, no-holds-barred spoof of Hollywood westerns, Mr. Wilder had the relatively quiet role of the Waco Kid, a boozy ex-gunfighter who helps an improbable black sheriff (Cleavon Little) save a town from railroad barons and venal politicians. The film’s once-daring humor may have lost some of its edge over the years, but Mr. Wilder’s next Brooks film, “Young Frankenstein,” has never grown old.

Mr. Wilder himself hatched the idea, envisioning a black-and-white film faithful to the look of the Boris Karloff “Frankenstein,” down to the laboratory equipment, but played for laughs rather than for horror. He would portray an American man of science, the grandson of the infamous Dr. Frankenstein, who tries to turn his back on his heritage (“that’s Frahn-kahn-STEEN”) but finds himself irresistibly drawn to Transylvania to duplicate his grandfather’s creation of a monster in a spooky mountaintop laboratory.

Mr. Brooks’s original reaction to the idea, Mr. Wilder recalled, was noncommittal: “Cute. That’s cute.” But he eventually came aboard as director and co-writer, and the two garnered an Oscar nomination for their screenplay.