Horizontal gene transfer plays a major role in microbial evolution. However, newly acquired sequences can decrease fitness unless integrated into preexisting regulatory networks. We found that the histone-like nucleoid structuring protein (H-NS) selectively silences horizontally acquired genes by targeting sequences with GC content lower than the resident genome. Mutations in hns are lethal in Salmonella unless accompanied by compensatory mutations in other regulatory loci. Thus, H-NS provides a previously unrecognized mechanism of bacterial defense against foreign DNA, enabling the acquisition of DNA from exogenous sources while avoiding detrimental consequences from unregulated expression of newly acquired genes. Characteristic GC/AT ratios of bacterial genomes may facilitate discrimination between a cell's own DNA and foreign DNA.