Beetles in the weevil subfamilies Scolytinae and Platypodinae are unusual in that they burrow as adults inside trees for feeding and oviposition. Some of these beetles are known as ambrosia beetles for their obligate mutualisms with asexual fungi--known as ambrosia fungi--that are derived from plant pathogens in the ascomycete group known as the ophiostomatoid fungi. Other beetles in these subfamilies are known as bark beetles and are associated with free-living, pathogenic ophiostomatoid fungi that facilitate beetle attack of phloem of trees with resin defenses. Using DNA sequences from six genes, including both copies of the nuclear gene encoding enolase, we performed a molecular phylogenetic study of bark and ambrosia beetles across these two subfamilies to establish the rate and direction of changes in life histories and their consequences for diversification. The ambrosia beetle habits have evolved repeatedly and are unreversed. The subfamily Platypodinae is derived from within the Scolytinae, near the tribe Scolytini. Comparison of the molecular branch lengths of ambrosia beetles and ambrosia fungi reveals a strong correlation, which a fungal molecular clock suggests spans 60 to 21 million years. Bark beetles have shifted from ancestral association with conifers to angiosperms and back again several times. Each shift to angiosperms is associated with elevated diversity, whereas the reverse shifts to conifers are associated with lowered diversity. The unusual habit of adult burrowing likely facilitated the diversification of these beetle-fungus associations, enabling them to use the biomass-rich resource that trees represent and set the stage for at least one origin of eusociality.