Pain is comprised of both sensory and affective components. The anterior cingulate cortex (ACC) is a key brain region involved in the emotional processing of pain. Specifically, glutamatergic transmission within the ACC has been shown to modulate pain-related aversion. In the present study, we use in vivo optogenetics to activate or silence, using channelrhodopsin (ChR2) and archaerhodopsin (ArchT) respectively, calmodulin-kinase II¿ (CaMKII¿)-expressing excitatory glutamatergic neurons of the ACC during a formalin-induced conditioned place aversion (F-CPA) behavioral paradigm in both female and male adult Sprague-Dawley rats. Expression of c-Fos, a marker of neuronal activity, was assessed within the ACC using immunohistochemistry. Optogenetic inhibition of glutamatergic neurons of the ACC abolished F-CPA without affecting formalin-induced nociceptive behavior during conditioning. In male rats, optogenetic activation of ACC glutamatergic neurons decreased formalin-induced nociceptive behavior during conditioning without affecting F-CPA. Interestingly, the opposite effect was seen in females, where optogenetic activation of glutamatergic neurons of the ACC increased formalin-induced nociceptive behavior during conditioning. The abolition of F-CPA following optogenetic inhibition of glutamatergic neurons of the ACC was associated with a reduction in c-Fos immunoreactivity in the ACC in male rats, but not female rats. These results suggest that excitatory glutamatergic neurons of the ACC play differential and sex-dependent roles in the aversion learning and acute sensory components of pain.