Neonatal pain-related stress is associated with elevated salivary cortisol levels to age 18 months in children born very preterm, compared to full-term, suggesting early programming effects. Importantly, interactions between immune/inflammatory and neuroendocrine systems may underlie programming effects. We examined whether cortisol changes persist to school age, and if common genetic variants in the promoter region of the NFKBIA gene involved in regulation of immune and inflammatory responses, modify the association between early experience and later life stress as indexed by hair cortisol levels, which provide an integrated index of endogenous HPA axis activity. Cortisol was assayed in hair samples from 128 children (83 born preterm =32 weeks gestation and 45 born full-term) without major sensory, motor or cognitive impairments at age 7 years. We found that hair cortisol levels were lower in preterm compared to term-born children. Downregulation of the HPA axis in preterm children without major impairment, seen years after neonatal stress terminated, suggests persistent alteration of stress system programming. Importantly, the etiology was gender-specific such that in preterm boys but not girls, specifically those with the minor allele for NFKBIA rs2233409, lower hair cortisol was associated with greater neonatal pain (number of skin-breaking procedures from birth to term), independent of medical confounders. Moreover, the minor allele (CT or TT) of NFKBIA rs2233409 was associated with higher secretion of inflammatory cytokines, supporting the hypothesis that neonatal pain-related stress may act as a proinflammatory stimulus that induces long-term immune cell activation. These findings are the first evidence that a long-term association between early pain-related stress and cortisol may be mediated by a genetic variants that regulate the activity of NF-?B, suggesting possible involvement of stress/inflammatory mechanisms in HPA programming in boys born very preterm.