Abstract. 1. Habitat loss and fragmentation is a leading cause of species extinction. This not only concerns loss of major habitats, but also loss of microclimatic heterogeneity within such habitats.2. In this study, we examine the effects of microclimate on the abundance and movements of Onthophagus gibbulus, a dung beetle associated with pastoral habitats. While formerly widespread in Southern Finland, the species is now critically endangered at a national level, persisting within an area of 6 km 2 . 3. We divided the Finnish distribution of O. gibbulus into 50 · 50-m grid cells, characterised local microclimate by incident solar radiation, and surveyed the distribution of O. gibbulus within a subset of cells. To investigate the impact of microclimatic conditions on dung beetle movements, we conducted a mark-release-recapture study.4. Our approach allowed us to estimate the national population size of O. gibbulusa figure rarely available for endangered insect species. The Finnish population of O. gibbulus comprises between 2000 and 6000 individuals.5. The abundance of beetles per dung pat increases with incident solar radiation, and beetles are more likely to move towards warmer than colder spots in the landscape.6. Overall, our study depicts O. gibbulus as a thermophile confined to the warmest part of the landscape, and offers loss of microclimatic variation as the cause for its largescale decline. To conserve O. gibbulus and similar species, we need to consider not only the amount of macrohabitats, but also the amount and distribution of microclimatic variation within them. Future predictions are complicated by ongoing climate change.