The current study aimed to understand the mediating and/or moderating role of prenatal hypothalamic–pituitary–adrenal (HPA) axis function in the association between maternal adverse childhood experiences (ACEs) and child internalizing and externalizing behavior problems at age 4. The influence of timing and child sex were also explored. Participants were 248 mother–child dyads enrolled in a prospective longitudinal cohort study (the Alberta Pregnancy Outcomes and Nutrition Study). Maternal ACEs were retrospectively assessed while maternal self-reported depression and diurnal salivary cortisol were assessed prospectively at 6–26 weeks gestation (T1) and 27–37 weeks gestation (T2). Maternal report of child internalizing and externalizing problems was assessed at 4 years (T3). Results revealed that there was a negative indirect association between maternal ACEs and child internalizing behavior via a higher maternal cortisol awakening response (CAR). Maternal diurnal cortisol slope moderated the association between maternal ACEs and child behavior problems. Some of these effects were dependent on child sex, such that higher ACEs and a flatter diurnal slope at T1 was associated with more internalizing behavior in female children and more externalizing behavior in male children. There were timing effects such that the mediating and moderating effects were strongest at T1.