Survival critically depends on selecting appropriate defensive or exploratory behaviors and is strongly influenced by the surrounding environment. Contextual discrimination is a fundamental process that is thought to depend on the prefrontal cortex to integrate sensory information from the environment and regulate adaptive responses to threat during uncertainty. However, the precise prefrontal circuits necessary for discriminating a previously threatening context from a neutral context remain unknown. Using a combination of single-unit recordings and optogenetic manipulations, we identified a neuronal subpopulation in the dorsal medial prefrontal cortex (dmPFC) that projects to the lateral and ventrolateral periaqueductal gray (l/vlPAG) and is selectively activated during contextual fear discrimination. Moreover, optogenetic activation and inhibition of this neuronal population promoted contextual fear discrimination and generalization, respectively. Our results identify a subpopulation of dmPFC-l/vlPAG-projecting neurons that control switching between different emotional states during contextual discrimination.