Plants and mushrooms produce toxins primarily for self-defense. These organisms have evolved over time to develop chemical compounds that deter herbivores and pathogens. For instance, the toxins in certain mushrooms can cause severe illness or even death, deterring animals from eating them. Similarly, plants like the foxglove produce cardiac glycosides that can be lethal to many animals.