More than eight million Britons - three-quarters of them women - suffer migraine attacks, which involve dizziness, nausea and headaches. Episodes can last from four to 72 hours.
The problem affects more people than diabetes, asthma and epilepsy combined, and is the sixth most common cause of disability in the world.
The researchers, whose findings are published in the American Journal of Medicine, said the impact of caffeine on migraines is complex because it depends on dose and frequency. And while it may trigger an attack, it can also have a painkilling effect.
Participants completed diaries twice a day for six weeks reporting on the frequency and severity of migraines and their intake of caffeinated drinks.
Fellow researcher Dr Suzanne Bertisch said: "There have been few studies on the immediate risk of migraines with daily changes in caffeine intake."
The cause of migraines is not fully understood. They are thought to occur when abnormal brain activity affects nerve signals, chemicals and blood vessels in the brain. Other potential triggers include stress, anxiety, depression, poor-quality sleep or hormonal changes during the menstrual cycle.
Dehydration, drinking too much alcohol and missed meals may also cause them.
Basic painkillers are often an effective treatment, although sleeping or lying down in a dark room are also recommended techniques.