The Omicron variant of SARS-CoV-2 evades neutralization by most serum antibodies elicited by two doses of mRNA vaccines, but a third dose of the same vaccine increases anti-Omicron neutralizing antibodies. By combining computational modeling with data from vaccinated humans we reveal mechanisms underlying this observation. After the first dose, limited antigen availability in germinal centers results in a response dominated by B cells with high germline affinities for immunodominant epitopes that are significantly mutated in an Omicron-like variant. After the second dose, expansion of these memory cells and differentiation into plasma cells shape antibody responses that are thus ineffective for such variants. However, in secondary germinal centers, pre-existing higher affinity antibodies mediate enhanced antigen presentation and they can also partially mask dominant epitopes. These effects generate memory B cells that target subdominant epitopes that are less mutated in Omicron. The third dose expands these cells and boosts anti-variant neutralizing antibodies.