Sunlight exposure is known to affect mood, learning, and cognition. However, the molecular and cellular mechanisms remain elusive. Here, we show that moderate UV exposure elevated blood urocanic acid (UCA), which then crossed the blood-brain barrier. Single-cell mass spectrometry and isotopic labeling revealed a novel intra-neuronal metabolic pathway converting UCA to glutamate (GLU) after UV exposure. This UV-triggered GLU synthesis promoted its packaging into synaptic vesicles and its release at glutamatergic terminals in the motor cortex and hippocampus. Related behaviors, like rotarod learning and object recognition memory, were enhanced after UV exposure. All UV-induced metabolic, electrophysiological, and behavioral effects could be reproduced by the intravenous injection of UCA and diminished by the application of inhibitor or short hairpin RNA (shRNA) against urocanase, an enzyme critical for the conversion of UCA to GLU. These findings reveal a new GLU biosynthetic pathway, which could contribute to some of the sunlight-induced neurobehavioral changes.