Bacterial immune systems, such as CRISPR-Cas, protect bacteria from viral infections by recognizing and cleaving foreign genetic material. These systems have been adapted for gene editing technologies, revolutionizing fields like genetics and biotechnology.