Organisms produce toxins primarily as a defense mechanism. Plants, for example, produce compounds like tannins to deter herbivores. Similarly, animals such as snakes produce venom to immobilize prey and defend against predators. Microorganisms may produce toxins as a way to outcompete other microbes or to inhibit the growth of competing species.