Although lacking an adaptive immune system and often living in habitats with dense and diverse bacterial populations, marine invertebrates thrive in the presence of potentially challenging microbial pathogens. However, the mechanisms underlying this resistance remain largely unexplored and promise to reveal novel strategies of microbial resistance. Here, we provide evidence that a mud-dwelling clam, Meretrix petechialis, synthesizes, stores, and secretes the antibiotic erythromycin. Liquid chromatography coupled with mass spectrometry, immunocytochemistry, fluorescence in situ hybridization, RNA interference, and enzyme-linked immunosorbent assay revealed that this potent macrolide antimicrobial, thought to be synthesized only by microorganisms, is produced by specific mucus-rich cells beneath the clam's mantle epithelium, which interfaces directly with the bacteria-rich environment. The antibacterial activity was confirmed by bacteriostatic assay. Genetic, ontogenetic, phylogenetic and genomic evidence, including genotypic segregation ratios in a family of full siblings, gene expression in clam larvae, phylogenetic tree, and synteny conservation in the related genome region further revealed that the genes responsible for erythromycin production are of animal origin. The detection of this antibiotic in another clam species showed that the production of this macrolide is not exclusive to M. petechialis and may be a common strategy among marine invertebrates. The finding of erythromycin production by a marine invertebrate offers a striking example of convergent evolution in secondary metabolite synthesis between the animal and bacterial domains. These findings open the possibility of engineering-animal tissues for the localized production of an antibacterial secondary metabolite.