Germinal centers (GCs) are specialized compartments within the secondary lymphoid organs, where B cells proliferate, differentiate, and mutate their antibody genes. Upon exit from the GC, B cells terminally differentiate into plasma cells or memory B cells. While we have a good comprehension of plasma cell differentiation, memory B cell differentiation is still incompletely understood. In this paper, we extend previous models of the molecular events underlying B cell differentiation with new findings regarding memory B cell formation, and present a quantitative stochastic model of the intracellular and extracellular dynamics governing B cell maturation and exit from the GC. To simulate this model, we develop a novel extension to the Gillespie algorithm that enables the efficient stochastic simulation of the system, while keeping track of individual cell properties. Our model is able to explain the dynamical shift from memory B cell to plasma cell production over the lifetime of a GC. Moreover, our results suggest that B cell fate selection can be explained as a process that depends fundamentally on antigen affinity.