Ramadan exposure in utero can be regarded as a natural experiment to study how nutritional conditions in utero influence susceptibility to disease later in life. We analyzed data from rural Burkina Faso on 41,025 children born between 1993 and 2012, of which 25,093 to Muslim mothers. Ramadan exposure was assigned based on overlap between Ramadan dates and gestation, creating seven exclusive categories. We used proportional hazards regression with difference-in-differences to estimate the association between Ramadan exposure at different gestational ages and under-five mortality. Under-five mortality was 32 deaths per 1,000 child-years. Under-five mortality among Muslims was 15% higher than among non-Muslims (P < 0.001). In the difference-in-differences analysis, Ramadan occurrence during conception, first, or second trimester was associated with higher under-five mortality rates, only among Muslims. The mortality rates of children born to Muslim mothers were 33%, 29% and 22% higher when Ramadan occurred during conception, first and second trimester, respectively, than among children of non-Muslim mothers born at the same time (P = 0.01, P < 0.001 and P = 0.007). Having a Muslim mother was not associated with mortality when not exposed to Ramadan, born during Ramadan or exposed during the third trimester. Observance of Ramadan during early pregnancy can have detrimental consequences for the future health of the unborn child.