Drinking an extra cup of coffee — or other caffeinated beverage — could up the odds of a migraine among those prone to getting them, a new study suggests.

Harvard researchers found that having a third cup of coffee, for example, if you regularly drink one to two, might trigger an extreme headache, according to the study published Thursday in The American Journal of Medicine.

“In patients with episodic migraine, one to two caffeinated drinks were not associated with getting a migraine on the same day,” said the study’s lead author, Elizabeth Mostofsky, a postdoctoral fellow at the Beth Israel Deaconess Medical Center and an instructor of epidemiology at Harvard’s T.H. Chan School of Public Health.

Three drinks, however, were linked to a greater risk of having a migraine that day, she said.

“These findings would suggest that you limit yourself to no more than two servings a day of caffeinated beverages,” Mostofsky told NBC News.

To look at the impact of caffeine on migraines, Mostofsky and her colleagues recruited 98 volunteers, the majority of whom were women, who experienced two to 15 headaches per month. The volunteers were asked to keep diaries that tracked lifestyle factors, such as caffeine and alcohol consumption, physical activity and stress levels, for at least six weeks.

The majority of the participants — 66 percent — reported consuming one to two caffeinated beverages a day, while 20 percent said they typically did not drink any caffeinated beverages. Twelve percent reported drinking three to four servings a day. In all, participants reported 825 migraines during the 4,467 days of the study.

For most, there didn’t seem to be an association between one or two caffeinated drinks and migraines, but among those who rarely consumed caffeine, just one or two servings could increase headache risk.

For those who normally had one or two servings a day, three or more caffeinated drinks were linked to an increased risk of headaches. And the risk rose as the number of servings increased: The people who consumed three or more servings had 1.4 times higher odds of a migraine on the same day, while those who consumed five or more servings had 2.61 times higher odds of headache on the same day.

The new findings back up what migraine experts have long suspected, said Dr. Laurie Knepper, an associate professor of neurology at the University of Pittsburgh and the UPMC Headache Center.

“We certainly counsel our patients to limit their intake of coffee to 8 to 12 ounces a day,” Knepper said. “It’s a good study and I’m not surprised to see that three or more servings set off migraines."

In other coffee news, another study published this week found that caffeinated drinks consumed within four hours of bedtime were not associated with shorter or disrupted sleep.

That study, published Monday in the journal Sleep, followed 785 African Americans who wore motion sensors while asleep and kept diaries detailing consumption of alcohol, nicotine and caffeine. Unlike caffeine, alcohol and nicotine within four hours of bedtime did affect how well people slept.

Follow NBC HEALTH on Twitter & Facebook.