Toll-like receptor (TLR) signaling is one of the most important signaling cascades of the innate immune system of vertebrates. Studies in invertebrates have focused on the fruit fly Drosophila melanogaster and the nematode Caenorhabditis elegans, and there is little information regarding the evolutionary origin and ancestral function of TLR signaling. In Drosophila, members of the Toll-like receptor family are involved in both embryonic development and innate immunity. In C. elegans, a clear immune function of the TLR homolog TOL-1 is controversial and central components of vertebrate TLR signaling including the key adapter protein myeloid differentiation primary response gene 88 (MyD88) and the transcription factor NF-κB are not present. In basal metazoans such as the cnidarians Hydra magnipapillata and Nematostella vectensis, all components of the vertebrate TLR signaling cascade are present, but their role in immunity is unknown. Here, we use a MyD88 loss-of-function approach in Hydra to demonstrate that recognition of bacteria is an ancestral function of TLR signaling and that this process contributes to both host-mediated recolonization by commensal bacteria as well as to defense against bacterial pathogens.