She suffered from terrible headaches for a long time.

Literal

She [topic-は] long-time terrible headache [by-に] was-afflicted.

悩まされた is the causative-passive of 悩む ('to suffer/worry'): 'was made to suffer' — the headache is the agent causing the suffering. This adversative passive construction casts the headache as something that acted upon her against her will. ひどい ('terrible/severe') intensifies the suffering.