Sometimes one person has to be sacrificed to save many more, even if it’s a teenager, according to ants. Researchers have found that a certain species will kill off young members of their own colony when those victims have contracted deadly fungal infections.

Before sickened Lasius neglectus ant pupae become contagious, but while they are releasing chemical cues of their illness, other ants rip them out of their cocoons and bite them, injecting an “antimicrobial poison which enters the body and prevents pathogen replication from the inside out,” a study in the journal eLife explains. Although the ant is killed, so is the potentially dangerous infection.

“In social groups, infections have the potential to spread rapidly and cause disease outbreaks,” the study says. “Ants live in crowded societies where disease can spread rapidly and take a heavy toll on the community.”

Their sacrificial process is known as “destructive disinfection” and spares the rest of the ant colony from what could be a serious outbreak.

“This is especially pertinent in the ants and termites, because their sedentary and territorial lifestyle makes it likely infectious corpses are encountered again, even if they are removed from the colony,” the authors noted. “Previous studies have shown that fungus-infected ants become highly contagious to nestmates after death and can cause epidemics that result in colony collapse.”

The euthanization occurs at the point when the ants can no longer care for the diseased pupae, according to Royal Holloway, University of London, but it is an evolutionary mechanism with an impact beyond just the drain on the colony’s health care resources.

“The ants do try to get rid of the fungus first,” researcher Sylvia Cremer explained in the university statement. “They care for the pathogen-contaminated colony members by intensively grooming their bodies to get rid of the fungus’ spores. If this doesn’t prevent infection, however, they kill the infected colony-members.”

For the study, the infection-causing fungus the researchers were looking at was Metarhizium brunneum. Sick ants release hydrocarbons that their comrades pick up, like signals.

“The ants could smell if members of their colony were fatally ill,” researcher Christopher Pull said in the statement. “This fungus becomes a danger to the whole colony if even one ant sporulates with it, so the ants have formulated an effective way to deal with it: kill their fatally infected colleagues.”