Objectives To determine if genetic variation in genes in the hypothalamic–pituitary–adrenal (HPA) axis, the primary stress response system, influences susceptibility to developing musculoskeletal pain. Methods Pain and comorbidity data was collected at three time points in a prospective population-based cohort study. Pairwise tagging single nucleotide polymorphisms (SNPs) were selected and genotyped for seven genes. Genetic association analysis was carried out using zero-inflated negative binomial regression to test for association between SNPs and the maximum number of pain sites across the three time points in participants reporting pain, reported as proportional changes with 95% CIs. SNPs were also tested for association with chronic widespread pain (CWP) using logistic regression reporting odds ratios and 95% CI. Results A total of 75 SNPs were successfully genotyped in 994 participants including 164 cases with persistent CWP and 172 pain-free controls. Multiple SNPs in SERPINA6 were associated with the maximum number of pain sites; for example, each copy of the T allele of rs941601 was associated with having 16% (proportional change=1.16, 95% CI 1.04 to 1.28, p=0.006) more pain sites compared to participants with the CC genotype. SERPINA6 gene SNPs were also associated with CWP. Significant associations between the maximum number of pain sites and SNPs in the CRHBP and POMC genes were also observed and a SNP in MC2R was also associated with CWP. Associations between SNPs and comorbidity of poor sleep quality and depression explained some of the associations observed. Conclusions Genetic variation in HPA axis genes was associated with musculoskeletal pain; however, some of the associations were explained by comorbidities. Replication of these findings is required in independent cohorts.