The last common metazoan ancestor (LCMA) emerged over half a billion years ago. These complex metazoans provided newly available niche space for viruses and microbes. Modern day contemporaries, such as cnidarians, suggest that the LCMA consisted of two cell layers: a basal endoderm and a mucus-secreting ectoderm, which formed a surface mucus layer (SML). Here we propose a model for the origin of metazoan immunity based on external and internal microbial selection mechanisms. In this model, the SML concentrated bacteria and their associated viruses (phage) through physical dynamics (that is, the slower flow fields near a diffusive boundary layer), which selected for mucin-binding capabilities. The concentration of phage within the SML provided the LCMA with an external microbial selective described by the bacteriophage adherence to mucus (BAM) model. In the BAM model, phage adhere to mucus protecting the metazoan host against invading, potentially pathogenic bacteria. The same fluid dynamics that concentrated phage and bacteria in the SML also concentrated eukaryotic viruses. As eukaryotic viruses competed for host intracellular niche space, those viruses that provided the LCMA with immune protection were maintained. If a resident virus became pathogenic or if a non-beneficial infection occurred, we propose that tumor necrosis factor (TNF)-mediated programmed cell death, as well as other apoptosis mechanisms, were utilized to remove virally infected cells. The ubiquity of the mucosal environment across metazoan phyla suggest that both BAM and TNF-induced apoptosis emerged during the Precambrian era and continue to drive the evolution of metazoan immunity.