The sorting of students into ability groups is one of the most common, controversial and long-examined educational practices. Ability grouping also mechanically changes peer groups. We provide novel evidence on the cognitive and non-cognitive impacts in early years, of being exposed to higher-ability classroom peers through being assigned to the top within-class ability group. We exploit panel data from the UK Millennium Cohort Study, which allows us to construct trajectories of the cognitive and non-cognitive development of children from birth to entry into primary school. The data also record school grouping policies and the specific within-class group assignment of each child, by subject. We combine these rich data with an instrumental variable design using child-level variation in group assignment due to month of birth, in order to measure the local average treatment effect (LATE) of being assigned to the highest-ability peer group. We find that if a marginal student is assigned higher-ability peers, this significantly reduces their cognitive achievement in mathematics, and has no impact on literacy. There are countervailing impacts on non-cognitive outcomes for the marginal student assigned higher-ability peers: although they are more motivated to study and parents respond with an improved home learning environment, these children have more study-related difficulties and their relations with their peers significantly worsen. These findings have important policy implications for the use and design of within-class ability grouping in early years.