Associate Prof Peter Fineran, of the Otago microbiology and immunology department, said some bacteria, such as E. coli and salmonella, which pose threats to food safety, were once "written off" as boringly predictable.
But recent insights, including from his own research, showed such bacteria "work as groups, not just as individuals".
Prof Fineran acknowledged that, on a larger scale, fish and birds gained some protective advantages by forming groups such as shoals or flocks.
And humans had evolved sophisticated immune systems that enabled our bodies to "fight the viral infections that render us ill".
People were susceptible to viruses such as influenza and measles, and bacteria also needed to defend themselves against viruses.
"Amazingly, bacteria — although single-celled organisms — often possess similar adaptive immunity, called CRISPR-Cas systems."
The findings by a team led by Prof Fineran appear in the international journal Molecular Cell.
People had long benefited by living in communities and bacteria also often shared resources in this way, but, through higher population density, they risked becoming more vulnerable to the spread of viruses.
His team’s research provided new insight into how groups of bacteria collectively defended against viral threats.
Individual bacteria sensed their population density by "talking" to each other using a form of chemical communication known as quorum sensing, Prof Fineran said.
"The higher the population density, the stronger the communication between cells becomes, which results in greater co-ordination of immune defences."
Adrian Patterson, a PhD student and the paper’s first author, said bacterial cells at greatest risk of virus spread acted by strengthening their existing immunity "by up to 500-fold".
The research was supported by a Rutherford Discovery Fellowship from the Royal Society of New Zealand, and its Marsden Fund.