Summary Objectives Headaches and long working hours are important issues for workers. This study investigated the association between hours worked and the prevalence of headaches, and how that association varies with physical activity. Study design Cross-sectional study with two-stage cluster sampling. Methods Using data from a nationally representative sample of households in Japan, people aged 20–65 years who worked ≥35 h/week were studied, and the cross-sectional association between the number of hours worked per week (35–45, 46–55 and >55 h/week) and the prevalence rates of headaches of different severity was evaluated. Results Of 721 workers, 307 reported experiencing at least one headache per month. Compared with working 35–45 h/week, the prevalence ratios of severe or disabling headaches among individuals working >55 h/week were 1.38 [95% confidence interval (CI) 1.06–1.78] and 1.63 (95% CI 1.09–2.43), respectively. After stratification by the level of physical activity, the prevalence ratios were greater in the low-physical-activity group: 1.56 (95% CI 1.11–2.19) for severe headaches and 2.20 (95% CI 1.31–3.68) for disabling headaches. The number of hours worked was not associated with headaches in the high-physical-activity group. Conclusions Among workers in the general population, long working hours were associated with the prevalence of headaches, and the association may depend on a lack of physical activity.