In bacteria, transformation and restriction-modification (R-M) systems play potentially antagonistic roles. While the former, proposed as a form of sexuality, relies on internalized foreign DNA to create genetic diversity, the latter degrade foreign DNA to protect from bacteriophage attack. The human pathogen Streptococcus pneumoniae is transformable and possesses either of two R-M systems, DpnI and DpnII, which respectively restrict methylated or unmethylated double-stranded (ds) DNA. S. pneumoniae DpnII strains possess DpnM, which methylates dsDNA to protect it from DpnII restriction, and a second methylase, DpnA, which is induced during competence for genetic transformation and is unusual in that it methylates single-stranded (ss) DNA. DpnA was tentatively ascribed the role of protecting internalized plasmids from DpnII restriction, but this seems unlikely in light of recent results establishing that pneumococcal transformation was not evolved to favor plasmid exchange. Here we validate an alternative hypothesis, showing that DpnA plays a crucial role in the protection of internalized foreign DNA, enabling exchange of pathogenicity islands and more generally of variable regions between pneumococcal isolates. We show that transformation of a 21.7 kb heterologous region is reduced by more than 4 logs in dpnA mutant cells and provide evidence that the specific induction of dpnA during competence is critical for full protection. We suggest that the integration of a restrictase/ssDNA-methylase couplet into the competence regulon maintains protection from bacteriophage attack whilst simultaneously enabling exchange of pathogenicicy islands. This protective role of DpnA is likely to be of particular importance for pneumococcal virulence by allowing free variation of capsule serotype in DpnII strains via integration of DpnI capsule loci, contributing to the documented escape of pneumococci from capsule-based vaccines. Generally, this finding is the first evidence for a mechanism that actively promotes genetic diversity of S. pneumoniae through programmed protection and incorporation of foreign DNA.