The prefrontal cortex and basal ganglia are deeply implicated in working memory. Both structures are subject to dopaminergic neuromodulation in a way that exerts a critical influence on the proper operation of working memory. We present a novel network model to elucidate the role of phasic dopamine in the interaction of these two structures in initiating and maintaining mnemonic activity. We argue that neuromodulation plays a critical role in protecting memories against both internal and external sources of noise. Increases in cortical gain engendered by prefrontal dopamine release help make memories robust against external distraction, but do not offer protection against internal noise accompanying recurrent cortical activity. Rather, the output of the basal ganglia provides the gating function of stabilization against noise and distraction by enhancing select memories through targeted disinhibition of cortex. Dopamine in the basal ganglia effectively locks this gate by influencing the stability of up and down states in the striatum. Dopamine's involvement in affective processing endows this gating with specificity to motivational salience. We model a spatial working memory task and show that these combined effects of dopamine lead to superior performance.