One stormy afternoon in Ljubljana, the capital of Slovenia, thunder rolled, a bolt of lightning streaked across the sky, and the television and air conditioner went dark in the apartment of a woman with electrodes implanted in her brain.

Lightning had struck the building.

But the appliances were not the only things affected. After about an hour, the woman, who had had the electrodes put in five years before to help with debilitating muscle spasms in her neck, noticed her symptoms coming back. When she went to see her doctors the next day, they found that the pacemaker-like stimulator that powered the electrodes had switched itself off in response to the lightning strike.

It may sound futuristic, but deep brain stimulation, or D.B.S., has a fairly long history. Surgeons operating on epileptic patients in the 1930s and 1940s found that removing small portions of the brain could quiet seizures. Later, researchers found that stimulating certain brain areas, instead of cutting them out, could quell the involuntary movements characteristic of Parkinson’s and other disorders.

Today some patients with diagnoses like epilepsy, obsessive compulsive disorder and painful muscle spasms who don’t respond to other treatments have surgery to implant electrodes on either side of the brain. The electrodes are attached to wires running down to a stimulator implanted in the chest or torso. The stimulator provides electrical impulses to keep symptoms in check, using a battery that in some models can be topped up with an antenna-equipped power pack that’s charged with a wall plug.

Just like people with pacemakers, those with D.B.S. implants must be careful about getting diagnostic MRIs and spending time around devices that generate electromagnetic fields. These could set up a current in the implants and cause injury or other issues, said Dusan Flisar, a neurologist in Slovenia who is an author of the paper. For instance, one study reported a case where a patient sustained permanent neurological damage when an MRI scan heated up a D.B.S. electrode.

“There are also environmental causes that can affect the proper functioning of this device,” Dr. Flisar said — namely, it appears, lightning strikes.

The woman who came to see Dr. Flisar after the storm was lucky: She had not been charging her implanted battery at the time, nor had she had the charger pack plugged into the wall. If either had been in use, the device and its accessories could have met the same fate as her TV and air conditioner. “The charger would be destroyed like other appliances and the patient injured if she was charging the stimulator during the event,” said Dr. Flisar.

Dr. Flisar and his colleagues recommend in their paper that patients plug their chargers into surge protectors, which will help protect them, and suggest that doctors tell patients to avoid charging during storms.

Fortunately, when he and his colleagues checked the woman’s implant, they found that it had not been damaged. A safety function designed by the manufacturer had taken its cue from the sudden current running through the house and caused the device to switch itself off, pre-empting any interference from the lightning. The programming was intact; the battery still had plenty of charge.

When they fired up the device, it worked perfectly, none the worse for the storm.