The Toll/interleukin-1 receptor (TIR) domain is a canonical component of animal and plant immune systems1,2. In plants, intracellular pathogen sensing by immune receptors triggers their TIR domains to generate a molecule that is a variant of cyclic ADP-ribose3,4. This molecule is hypothesized to mediate plant cell death through a pathway that has yet to be resolved5. TIR domains have also been shown to be involved in a bacterial anti-phage defence system called Thoeris6, but the mechanism of Thoeris defence remained unknown. Here we show that phage infection triggers Thoeris TIR-domain proteins to produce an isomer of cyclic ADP-ribose. This molecular signal activates a second protein, ThsA, which then depletes the cell of the essential molecule nicotinamide adenine dinucleotide (NAD) and leads to abortive infection and cell death. We also show that, similar to eukaryotic innate immune systems, bacterial TIR-domain proteins determine the immunological specificity to the invading pathogen. Our results describe an antiviral signalling pathway in bacteria, and suggest that the generation of intracellular signalling molecules is an ancient immunological function of TIR domains that is conserved in both plant and bacterial immunity.