You might enjoy the kick that peppers add to salsa or chili. But from the chili pepper’s point of view, that heat fulfills the same function as the cyanide in apple seeds—it defends the plants from invading microbes that want to eat them.

When insects bore into a pepper, fungi have a chance to get through the tough outer skin and inside the fruit. But chili peppers develop piquant chemicals to thwart the harmful microbes long enough to give birds and other animals a chance to disperse the pepper seeds, helping the chilies to procreate, scientists found [National Geographic].

In fact, according to the new research, the peppers varied their amount of heat by how large the threat of fungal infection was. In insect-rich parts of Bolivia, where the University of Washington scientists did their study, chilies are chock full of capsaicinoids—the chemicals that give peppers their kick. On the other hand, peppers growing in areas where there are few insects, and thus little of the fungus, didn’t bother to produce much capsaicin, some being as mild as bell peppers, the researchers found [AP].

The remaining question, then, is why humans enjoy eating peppers full of spicy chemicals. People might have developed a taste for the powerful chile to take advantage of its anti-microbial powers. “That may not have been an accident,” said UW biologist Joshua Tewksbury, lead author of the study. “Eating chiles might have been very beneficial” [The Oregonian].