Following repeated opioid use, some dependent individuals experience persistent cognitive deficits that contribute to relapse of drug-taking behaviors, and one component of this response may be mediated by the endogenous dynorphin/kappa opioid system in neocortex. In C57BL/6 male mice, we find that acute morphine withdrawal evokes dynorphin release in the medial prefrontal cortex (PFC) and disrupts cognitive function by activation of local kappa opioid receptors (KORs). Immunohistochemical analyses using a phospho-KOR antibody confirmed that both withdrawal-induced and optically evoked dynorphin release activated KOR in PFC. Using a genetically encoded sensor based on inert KOR (kLight1.2a), we revealed the in vivo dynamics of endogenous dynorphin release in the PFC. Local activation of KOR in PFC produced multi-phasic disruptions of memory processing in an operant-delayed alternation behavioral task, which manifest as reductions in response number and accuracy during early and late phases of an operant session. Local pretreatment in PFC with the selective KOR antagonist norbinaltorphimine (norBNI) blocked the disruptive effect of systemic KOR activation during both early and late phases of the session. The early, but not late phase disruption was blocked by viral excision of PFC KORs, suggesting an anatomically dissociable contribution of pre- and postsynaptic KORs. Naloxone-precipitated withdrawal in morphine-dependent mice or optical stimulation of pdynCre neurons using Channelrhodopsin-2 disrupted delayed alternation performance, and the dynorphin-induced effect was blocked by local norBNI. Our findings describe a mechanism for control of cortical function during opioid dependence and suggest that KOR antagonism could promote abstinence.