Ecological change provokes speciation and extinction, but our knowledge of the interplay among the biotic and abiotic drivers of macroevolution remains limited. Using the unparalleled fossil record of Cenozoic macroperforate planktonic foraminifera, we demonstrate that macroevolutionary dynamics depend on the interaction between species' ecology and the changing climate. This interplay drives diversification but differs between speciation probability and extinction risk: Speciation was more strongly shaped by diversity dependence than by climate change, whereas the reverse was true for extinction. Crucially, no single ecology was optimal in all environments, and species with distinct ecologies had significantly different probabilities of speciation and extinction. The ensuing macroevolutionary dynamics depend fundamentally on the ecological structure of species' assemblages.