We study the treatment effect of grade retention using a panel of French junior high-school students, taking unobserved heterogeneity and the endogeneity of grade repetitions into account. We specify a multistage model of human-capital accumulation with a finite number of types representing unobserved individual characteristics. Class-size and latent student-performance indices are assumed to follow finite mixtures of normal distributions. Grade retention may increase or decrease the student’s knowledge capital in a type-dependent way. Our estimation results show that the average treatment effect on the treated (ATT) of grade retention on test scores is positive but small at the end of grade 9. Treatment effects are heterogeneous: we find that the ATT of grade retention is higher for the weakest students. We also show that class size is endogenous and tends to increase with unobserved student ability. The average treatment effect of grade retention is negative, again with the exception of the weakest group of students. Grade repetitions reduce the probability of access to grade 9 of all student types.