Stress is a major risk factor for the onset of many psychiatric diseases. In rodent models, chronic stress induces depression and impairs excitatory neurotransmission. However, little is known about the effect of stress on synaptic circuitry during the development of behavioral symptoms. Using two-photon transcranial imaging, we studied the effect of repeated restraint stress on dendritic spine plasticity in the frontal cortex in vivo. We found that restraint stress induced dendritic spine loss by decreasing the rate of spine formation and increasing the rate of spine elimination. The N-methyl-d-aspartate receptor antagonist ketamine inhibited stress-induced spine loss mainly by protecting mushroom spines from elimination. Ketamine also induced re-formation of spines in close proximity to previously stress-eliminated spines. Electrophysiological and in vivo imaging experiments showed that ketamine enhanced activity of parvalbumin (PV) interneurons under stress and counterbalanced the stress-induced net loss of PV axonal boutons. In addition, selective chemogenetic excitation of PV interneurons mimicked the protective effects of ketamine on dendritic spines against stress. Collectively, our data provide new insights on the effects of ketamine on synaptic circuitry under stress and a possible mechanism to counteract stress-induced synaptic impairments through PV interneuron activation.