Migraines and headaches affect billions of people worldwide, and a new study suggests the drug ubrogepant can put a stop to the pain even before a migraine has fully kicked in.

Sold under the brand name Ubrelvy, ubrogepant is already used to treat migraines, but researchers in the US wanted to see if it could get to work ahead of time. The study was funded by the drug's developer, pharmaceutical company AbbVie.

Ubrogepant was administered during what's known as the migraine prodrome – when symptoms such as sensitivity to light start to be felt, but before the worst of the pain has started.

The drug works by inhibiting a protein called CGRP (calcitonin gene-related peptide) that plays a key role in migraines.

"Based on our findings, treatment with ubrogepant may allow people with migraine who experience early warning signs before a migraine occurs to quickly treat migraine attacks in their earliest stages and go about their daily lives with little discomfort and disruption," says neurologist Richard Lipton, from the Albert Einstein College of Medicine in New York City.

Over 400 adults completed the study, all with a history of migraines who could recognize the onset of the migraine prodrome. The team randomly allocated them into two groups: one taking ubrogepant before migraine pain, and the other taking a placebo.

Participants were then asked to rate how their migraine was affecting them 24 hours later: 65 percent of the ubrogepant group said they were "not at all limited" or "a little limited" by pain at that stage, compared to 48 percent of the placebo group.

The drug seems to be fast-acting too: just two hours after medication, people taking the drug were already significantly more likely to report "no disability, able to function normally" than those taking the placebo.

"Improving care at the first signs of migraine, even before headache pain begins, can be a key to improved outcomes," says Lipton. "Our findings are encouraging, suggesting that ubrogepant may help people with migraine function normally and go about their day."

It's worth noting that the study relies on self reporting from the participants rather than any clinical measurement, and that an early ubrogepant dose didn't work for everyone every time, but it's an encouraging finding for migraine sufferers.

The effectiveness of this treatment does rely on being able to feel a migraine coming on 24 to 48 hours ahead of time, through symptoms such as light sensitivity and mood changes – that's not something everyone can do, though more severe migraines are usually associated with more noticeable prodrome symptoms.

We still don't know exactly what causes migraines, but their intensity can leave people unable to function properly. Research like this is important to improve our understanding of how migraines work, and how they can be stopped.

"This could lead to an improved quality of life for those living with migraine," says Lipton.

The research has been published in Neurology.