For most cases of esophageal spasms, doctors recommend that patients avoid certain foods or situations that can trigger an attack, notes Mayo Clinic. Doctors also recommend that the patient treats the underlying condition causing the spasms, such as depression, anxiety or gastroesophageal reflux disease.
If the esophageal spasms are severe, a doctor may prescribe medications such as nitroglycerin given under the tongue to help calm a random spasm and calcium channel blockers for long-lasting relief, notes MedlinePlus. Doctors also give low doses of anti-depressants, including trazodone or nortriptyline, to ease spasms. If the spasms are very severe, the doctor may dilate the esophagus, which requires surgery.