Defense-associated reverse transcriptase (DRT) systems perform DNA synthesis to protect bacteria against viral infection, but the identities and functions of their DNA products remain largely unknown. We show that DRT2 systems encode an unprecedented immune pathway that involves de novo gene synthesis through rolling circle reverse transcription of a noncoding RNA (ncRNA). Programmed template jumping on the ncRNA generates a concatemeric cDNA, which becomes double-stranded upon viral infection. This DNA product constitutes a protein-coding, nearly endless open reading frame (neo) gene whose expression leads to potent cell growth arrest, restricting the viral infection. Our work highlights an elegant expansion of genome coding potential through RNA-templated gene creation and challenges conventional paradigms of genetic information encoded along the one-dimensional axis of genomic DNA.