The end-Permian mass extinction (EPME) led to a severe terrestrial ecosystem collapse. However, the ecological response of insects—the most diverse group of organisms on Earth—to the EPME remains poorly understood. Here, we analyse beetle evolutionary history based on taxonomic diversity, morphological disparity, phylogeny, and ecological shifts from the Early Permian to Middle Triassic, using a comprehensive new data set. Permian beetles were dominated by xylophagous stem groups with a high diversity and disparity, which probably played an underappreciated role in the Permian carbon cycle. Our suite of analyses shows that Permian xylophagous beetles suffered a severe extinction during the EPME largely due to the collapse of forest ecosystems, resulting in an Early Triassic gap of xylophagous beetles. New xylophagous beetles appeared widely in the early Middle Triassic, which is consistent with the restoration of forest ecosystems. Our results highlight the ecological significance of insects in deep-time terrestrial ecosystems.