Escovopsis has evolved defenses against the bacteria, producing compounds that inhibit their growth. And yet the ants still manage to keep these pathogens in check.

Dr. Marvasi and his co-authors — Ayush Pathak of Imperial College London and Steve Kett of Middlesex University London — argue that we would do well to look more closely at the ants to figure out the secrets to their success.

One important advantage is that the bacteria on ants make several antimicrobials at once. “It’s an impressive chemical factory,” said Dr. Marvasi.

Powerful evolutionary forces create this variety, said Sarah Worsley, a senior research associate at the University of East Anglia in England, who was not involved in the new study.

When the ants forage for garden fertilizer, they pick up random bacteria from the ground. These compete fiercely with the resident microbes for the nutrients provided by the ant glands. Natural selection favors the residents that make powerful antimicrobials that ward off the newcomers.

“These antimicrobials are being produced as a result of this warfare on the ant’s surface,” said Dr. Worsley. “The ants get in on the competition and use those antimicrobials to look after their fungus gardens.”

Researchers are also learning how new antimicrobials evolve. “We’re accumulating so much new information on the molecular level now,” said Katrin Kellner, a molecular ecologist at the University of Texas at Tyler.