Most modern mammals, including strictly diurnal species, exhibit sensory adaptations to nocturnal activity that are thought to be the result of a prolonged nocturnal phase or 'bottleneck' during early mammalian evolution. Nocturnality may have allowed mammals to avoid antagonistic interactions with diurnal dinosaurs during the Mesozoic. However, understanding the evolution of mammalian activity patterns is hindered by scant and ambiguous fossil evidence. While ancestral reconstructions of behavioural traits from extant species have the potential to elucidate these patterns, existing studies have been limited in taxonomic scope. Here, we use an extensive behavioural dataset for 2,415 species from all extant orders to reconstruct ancestral activity patterns across Mammalia. We find strong support for the nocturnal origin of mammals and the Cenozoic appearance of diurnality, although cathemerality (mixed diel periodicity) may have appeared in the late Cretaceous. Simian primates are among the earliest mammals to exhibit strict diurnal activity, some 52-33 million years ago. Our study is consistent with the hypothesis that temporal partitioning between early mammals and dinosaurs during the Mesozoic led to a mammalian nocturnal bottleneck, but also demonstrates the need for improved phylogenetic estimates for Mammalia.