Over 90 capsular serotypes of Streptococcus pneumoniae, a common nasopharyngeal colonizer and major cause of pneumonia, bacteremia, and meningitis, are known. It is unclear why some serotypes can persist at all: They are more easily cleared from carriage and compete poorly in vivo. Serotype-specific immune responses, which could promote diversity in principle, are weak enough to allow repeated colonizations by the same type. We show that weak serotype-specific immunity and an acquired response not specific to the capsule can together reproduce observed diversity. Serotype-specific immunity stabilizes competition, and acquired immunity to noncapsular antigens reduces fitness differences. Our model can be used to explain the effects of pneumococcal vaccination and indicates general factors that regulate the diversity of pathogens.