The primary function of fruit is to attract animals that disperse viable seeds, but the nutritional rewards that attract beneficial consumers also attract consumers that kill seeds instead of dispersing them. Many of these unwanted consumers are microbes, and microbial defense is commonly invoked to explain the bitter, distasteful, occasionally toxic chemicals found in many ripe fruits. This explanation has been criticized, however, due to a lack of evidence that microbial consumers influence fruit chemistry in wild populations. In the present study, we use wild chilies to show that chemical defense of ripe fruit reflects variation in the risk of microbial attack. Capsaicinoids are the chemicals responsible for the well known pungency of chili fruits. Capsicum chacoense is naturally polymorphic for the production of capsaicinoids and displays geographic variation in the proportion of individual plants in a population that produce capsaicinoids. We show that this variation is directly linked to variation in the damage caused by a fungal pathogen of chili seeds. We find that Fusarium fungus is the primary cause of predispersal chili seed mortality, and we experimentally demonstrate that capsaicinoids protect chili seeds from Fusarium. Further, foraging by hemipteran insects facilitates the entry of Fusarium into fruits, and we show that variation in hemipteran foraging pressure among chili populations predicts the proportion of plants in a population producing capsaicinoids. These results suggest that the pungency in chilies may be an adaptive response to selection by a microbial pathogen, supporting the influence of microbial consumers on fruit chemistry.