This study investigated individual and contextual factors associated with the duration of diarrhoeal episodes in 693 young children living in a large Brazilian city who were followed-up for at least 3 months. The outcome is analysed as a continuous variable, by means of a hierarchical conceptual model organizing the factors in meaningful blocks. A total of 2397 episodes were recorded (median duration 2 days, interquartile range 1–3 days). Low percentage of households connected to the sewerage system in the neighbourhood, low family purchasing power, high agglomeration, mother aged <19 years, low zinc content in child's diet, and episode severity were significantly associated with longer duration (0·26–0·69 days more). Purchasing power effect was largely mediated by environmental conditions, characteristics of the child, and hygienic behaviour. Environmental conditions acted as a possible effect modifier, enhancing the effect on duration of diarrhoea of the child not having being vaccinated against measles or breastfed for >6 months.