The construction of nests to rear offspring is restricted to vertebrates and few insect taxa, such as termites, wasps, and bees. Among bees, species of the family Megachilidae are characterized by a particularly high diversity in nest construction behaviour. Many megachilid bees nest in excavated burrows in the ground, others place their brood cells in a variety of above-ground cavities or attach them to the surface of a substrate, and yet others have adopted a kleptoparasitic habit. Evolutionary transitions between the different nesting sites and between conventional nesting and kleptoparasitism in bees are poorly understood. In the present study, we traced the evolution of nesting site selection and kleptoparasitism in the Annosmia–Hoplitis group (Osmiini), which displays an exceptionally high diversity in nesting behaviour. We found that the evolution of nesting behaviour proceeded unidirectionally from nesting in excavated burrows in the ground to nesting in rock depressions and cavities, followed by the colonization of snail shells and insect borings in dead wood or hollow stems. Kleptoparasitism evolved once and the kleptoparasitic species have derived from the same lineage as their hosts. © 2012 The Linnean Society of London, Biological Journal of the Linnean Society, 2012, 108, 349–360.