This randomised clinical trial aimed to evaluate the effect of a pro-breast-feeding (BF) and healthy complementary feeding intervention performed during infants’ first months of life on ultraprocessed food (UPF) consumption at 4–7 years. We enrolled 323 teenage mothers and their infants from South Brazil, 163 allocated to the intervention group and 160 to the control group. Intervention consisted of sessions on BF and healthy complementary feeding promotion and was carried out in the maternity ward and at home after delivery. Food consumption was assessed using three 24-h food recalls at child’s age of 4–7 years. Foods were classified according to NOVA classification. Dietary contribution of UPF was adjusted for intra-individual variability by the SPADE method and categorised into tertiles. We used Poisson regression models with robust variance, adjusted for confounders, to estimate the effect of the intervention and duration of BF on the risk of high consumption of UPF. Our final analysis included 194 children, with mean age of 6·1 (sd 0·5) years. Mean dietary contribution of UPF was 38 % in the intervention group and 42·7 % in the control group, from total daily intakes. Results adjusted for BF duration, propensity score, income and total energy content demonstrated that the intervention reduced the risk of high consumption of UPF by 35 % (relative risk 0·65, 95 % CI 0·43, 0·98). BF duration was not associated with UPF consumption. The intervention was effective in reducing the risk of high UPF consumption at the age of 4–7 years.