How fish larvae are protected from infection before the maturation of adaptive immunity, a process which may take up to several weeks in most species, has long been a matter of speculation. Using a germ-free model, we show that colonization by commensals in newly hatched zebrafish primes neutrophils and induces several genes encoding proinflammatory and antiviral mediators, increasing the resistance of larvae to viral infection. Commensal microbe recognition was found to be mediated mainly through a TLR/MyD88 signaling pathway, and professional phagocytes were identified as the source of these immune mediators. However, the induction of proinflammatory and antiviral genes, but not of antimicrobial effector genes, also required the covalent modification of histone H3 at gene promoters. Interestingly, chromatin modifications were not altered by commensal microbes or hatching. Taken together, our results demonstrate that gene-specific chromatin modifications are associated with the protection of zebrafish larvae against infectious agents before adaptive immunity has developed and prevent pathologies associated with excessive inflammation during development.