Social organisms are exposed to many pathogens, and have evolved various defence mechanisms to limit the cost of parasitism. Here we report the first evidence that ants use plant compounds as a collective mean of defence against microorganisms. The wood ants Formica paralugubris often incorporate large quantities of solidified conifer resin into their nests. By creating resin-free and resin-rich experimental nests, we demonstrate that this resin inhibits the growth of microorganisms in a context mimicking natural conditions. Such a collective medication probably confers major ecological advantages, and may be an unrecognized yet common feature of large, complex and successful societies.