A hallmark of addiction is the ability of drugs of abuse to trigger relapse after periods of prolonged abstinence. Here, we describe an epigenetic mechanism whereby chronic cocaine exposure causes lasting chromatin and downstream transcriptional modifications in the nucleus accumbens (NAc), a critical brain region controlling motivation. We link prolonged withdrawal from cocaine to the depletion of the histone variant H2A.Z, coupled with increased genome accessibility and latent priming of gene transcription, in D1 dopamine receptor-expressing medium spiny neurons (D1 MSNs) that relate to aberrant gene expression upon drug relapse. The histone chaperone ANP32E removes H2A.Z from chromatin, and we demonstrate that D1 MSN-selective Anp32e knockdown prevents cocaine-induced H2A.Z depletion and blocks cocaine's rewarding actions. By contrast, very different effects of cocaine exposure, withdrawal, and relapse were found for D2 MSNs. These findings establish histone variant exchange as an important mechanism and clinical target engaged by drugs of abuse to corrupt brain function and behavior.