The mechanism by which acute pain or itch information at the periphery is processed in the primary somatosensory cortex (S1) remains unclear. To elucidate this, we used a viral-mediated targeted-recombination-in-active population system to target S1 neuronal ensembles that are active during pain or itch sensations. We induced the expression of excitatory or inhibitory designer receptors exclusively activated by designer drugs in pain- or itch-related S1 neurons. We identified neuronal populations in mice that regulate the sensory components of pain and itch in the S1 hind paw region. Notably, the neuronal circuit between pain-related S1 neurons and the parafascicular nucleus contributed to hyperalgesia and anxiety-like behavior. We propose that S1 plays an essential role in sensory and affective responses to noxious stimuli, such as pain.