In this secondary analysis of mobile health headache diary data, we evaluated the relationship between adherence to medication used for the acute treatment of migraine and lifetime history of an anxiety or depression disorder. Medication non-adherence can produce poor clinical efficacy and may be associated with medication overuse. Medication overuse was defined by taking a migraine-specific medication (MSM) for ≥10 days/month, an opioid or barbiturate for ≥10 days/month, or a nonsteroidal anti-inflammatory drug for ≥15 days/month and having ≥15 headache days/month. Extant literature predominantly evaluates fixed-schedule medication adherence. Little is known about predictors of adherence to as-needed medication such as those used for the acute treatment of migraine. Adults with prior migraine diagnosis and at least 4 headache days/month completed baseline questionnaires assessing lifetime history of depression or anxiety disorder diagnoses and were asked to record 90 days of once-daily electronic headache diaries soliciting: Headache occurrence; symptoms; medication taken, if any, for the acute treatment of migraine; and their pain level (mild, moderate, severe) when the medication was taken. The 193 participants who completed ≥30 days of headache diary were included in this secondary analysis. A MSM was used as the first medication taken on 45.7% (2825/6176) of headache days. Nearly a quarter of the sample (45/193, 23.3%) overused medications for acute treatment of migraine. Medication overuse was more common in patients with a history of an anxiety disorder, odds ratio (OR) 2.01 (95% confidence interval [CI] 1.01-3.69), but this relationship was not significant when headache days were accounted for, OR 2.02 (95% CI 0.83-4.91). Neither a history of a depression disorder, OR 1.40 (95% CI 0.90-2.16), nor an anxiety disorder, OR 1.11 (95% CI 0.71-1.72), was associated with taking medications early; however, duration of self-monitoring was associated with taking MSM early, OR 1.006 (95% CI 1.004-1.009). Lifetime history of depression and anxiety were not associated with taking a MSM early. Medication overuse may be more common in patients who have both migraine and anxiety. Taking a MSM early improved over time for all participants, even when adjusting for a history of an anxiety and or a depression disorder.