In 2371 Data installed the emotion chip created by Noonien Soong, giving him real feelings for the first time and overwhelming him at first.
Dr. Noonien Soong built an emotion chip for Data and meant to give it to him in 2367, but Lore took it before Data could receive it. Data recovered the chip from Lore in 2370 and kept it for some time before deciding to install it in 2371.
The chip worked, but the sudden feelings overwhelmed Data, who at times laughed or panicked uncontrollably and could not remove it because it had fused with his neural net. By the end of the Veridian III incident he was learning to live with it, and he later gained the ability to switch his emotions off.