The origin and radiation of mammals are key events in the history of life, with fossils placing the origin at 220 million years ago, in the Late Triassic period1. The earliest mammals, representing the first 50 million years of their evolution and including the most basal taxa, are widely considered to be generalized insectivores1, 2. This implies that the first phase of the mammalian radiation—associated with the appearance in the fossil record of important innovations such as heterodont dentition, diphyodonty and the dentary–squamosal jaw joint1, 3—was decoupled from ecomorphological diversification2, 4. Finds of exceptionally complete specimens of later Mesozoic mammals have revealed greater ecomorphological diversity than previously suspected, including adaptations for swimming, burrowing, digging and even gliding2, 5, 6, but such well-preserved fossils of earlier mammals do not exist1, and robust analysis of their ecomorphological diversity has previously been lacking. Here we present the results of an integrated analysis, using synchrotron X-ray tomography and analyses of biomechanics, finite element models and tooth microwear textures. We find significant differences in function and dietary ecology between two of the earliest mammaliaform taxa, Morganucodon and Kuehneotherium—taxa that are central to the debate on mammalian evolution. Morganucodon possessed comparatively more forceful and robust jaws and consumed ‘harder’ prey, comparable to extant small-bodied mammals that eat considerable amounts of coleopterans. Kuehneotherium ingested a diet comparable to extant mixed feeders and specialists on ‘soft’ prey such as lepidopterans. Our results reveal previously hidden trophic specialization at the base of the mammalian radiation; hence even the earliest mammaliaforms were beginning to diversify—morphologically, functionally and ecologically. In contrast to the prevailing view2, 4, this pattern suggests that lineage splitting during the earliest stages of mammalian evolution was associated with ecomorphological specialization and niche partitioning.