Medullary thymic epithelial cells (mTECs) expressing the autoimmune regulator AIRE and various tissue-specific antigens (TSAs) are critical for preventing the onset of autoimmunity and may attenuate tumor immunity. However, molecular mechanisms controlling mTEC development remain elusive. Here, we describe the roles of the transcription factor Spi-B in mTEC development. Spi-B is rapidly up-regulated by receptor activator of NF-κB ligand (RANKL) cytokine signaling, which triggers mTEC differentiation, and in turn up-regulates CD80, CD86, some TSAs, and the natural inhibitor of RANKL signaling, osteoprotegerin (OPG). Spi-B-mediated OPG expression limits mTEC development in neonates but not in embryos, suggesting developmental stage-specific negative feedback regulation. OPG-mediated negative regulation attenuates cellularity of thymic regulatory T cells and tumor development in vivo. Hence, these data suggest that this negative RANKL-Spi-B-OPG feedback mechanism finely tunes mTEC development and function and may optimize the trade-off between prevention of autoimmunity and induction of antitumor immunity.