After several weeks of training, the rats were given a mild foot shock whenever self-administering, causing 70 percent of them to give up the drug, the researchers wrote in the journal Nature.
But a "compulsive" minority kept coming back, just like human addicts.
The team measured brain activity in the prelimbic cortex, a part of the prefrontal cortex involved in impulse control, in both sets of rats.
They found that the activity was decreased in both groups, but markedly more so in the compulsive group.
When the researchers "turned on" the inactive neurons using optogenetic stimulation, the compulsive cocaine-seeking behaviour stopped, author Antonello Bonci of the National Institute on Drug Abuse in Maryland told AFP.
Conversely, they could also turn the non-compulsive rats into coke fiends by inhibiting the neurons.
"This new research ... shows that stimulation to that part of the brain decreases addictive behaviours such as cocaine seeking," Bonci said by email.
He said the findings held promise for humans, noting previous studies that have shown reduced activity in the prefrontal cortex of cocaine users.
In humans, however, a non-invasive type of stimulation would be used such as transcranial magnetic stimulation (TMS), in which magnetic pulses stimulate a small area on the surface of the brain.
By contrast, the optogenetic stimulation used with rats involves implanting fibre optics in an animal's brain to excite or inhibit brain cells in response to light stimuli.
Non-invasive brain stimulation techniques such as TMS are already used to treat a variety of conditions in humans, including depression.
"Our results can be immediately translated to clinical research settings with humans," Bonci said.
"In fact, we are planning clinical trials to use non-invasive brain stimulation methodologies such as TMS."
The same brain region may not be involved in addiction to all drugs, or in all people, Bonci noted.
"My speculation and hope is that we might have cases where a simple increase of activity in a brain region such as the prelimbic region can decrease symptoms, but we are far from a therapy for all drugs of abuse."