Mothers vary in duration of breastfeeding. These individual differences are related to a variety of demographic and individual maternal factors including maternal hormones, mood and early experiences. However, little is known about the role of genetic factors. We studied single-nucleotide polymorphisms (SNPs) in the OXT peptide gene (rs2740210; rs4813627) and the OXT receptor gene (OXTR rs237885) in two samples of mothers from the Maternal adversity, Vulnerability and Neurodevelopment study (MAVAN), a multicenter (Hamilton and Montreal, Canada) study following mothers and their children from pregnancy until 7 years of age. Data from the Hamilton site was the primary sample (n = 201) and data from Montreal was the replication sample (n = 151). Breastfeeding duration, maternal mood (measured by the CES-D scale) and early life adversity (measured by the CTQ scale) were established during 12 months postpartum. In our primary sample, polymorphisms in OXT rs2740210, but not the other SNPs, interacted with early life adversity to predict variation in breastfeeding duration (overall F8,125 = 2.361, P = 0.021; interaction effect b = -8.12, t = -2.3, P = 0.023) and depression (overall F8,118 = 5.751, P ≤ 0.001; interaction effect b = 6.06, t = 3.13, P = 0.002). A moderated mediation model showed that higher levels of depression mediated the inverse relation of high levels of early life adversity to breastfeeding duration, but only in women possessing the CC genotype [effect a’ = -3.3401, 95% confidence interval (CI) = -7.9466 to -0.0015] of the OXT SNP and not in women with the AA/AC genotype (a’ = -1.2942, ns). The latter findings (moderated mediation model) were replicated in our Montreal sample (a’ = -0.277, 95% CI = -0.7987 to -0.0348 for CC; a’ = -0.1820, ns for AA/AC).