Childhood obesity is a major public health concern, and the global rate is rising. Rapid infant weight gain is a risk factor for later overweight. Studies have linked prenatal ambient temperature exposure to fetal growth, and preliminary evidence suggests postnatal exposure may be associated with infant weight gain. Using a population-based historical cohort study including 1100576 infants born 2011-2019, we assessed the relationship between prenatal and one-month postnatal ambient temperature exposure and rapid infant weight gain. We used a hybrid spatiotemporal model to assess temperatures at the family's recorded residence at birth. Repeated weight measurements between birth and 15 months were used to model the outcome using the SuperImposition by Translation and Rotation (SITAR) method. We employed generalized linear models and distributed lag models to estimate the association between prenatal and postnatal exposure and rapid infant weight gain, defined as the upper tertile of the SITAR growth velocity. Overall, higher ambient temperatures were associated with rapid infant weight gain. The cumulative adjusted relative risk for the highest exposure quintile during pregnancy compared with the lowest quintile was 1.33 [95% confidence interval (CI): 1.25, 1.40], and the corresponding association for the first postnatal month was 1.19 (95% CI: 1.15, 1.23). Exposure to high ambient temperature during early and mid-pregnancy, as well as the first postnatal month, was associated with rapid weight gain, while during late pregnancy, exposure to low temperatures was associated with this outcome. Prenatal and postnatal ambient temperatures are associated with rapid infant weight gain.