The beetle series Staphyliniformia exhibits extraordinary taxonomic, ecological and morphological diversity. To gain further insight into staphyliniform relationships and evolution, we reconstructed the phylogeny of Staphyliniformia using DNA sequences from nuclear 28S rDNA and the nuclear protein-coding gene CAD for 282 species representing all living families and most subfamilies, a representative sample of Scarabaeiformia serving as a near outgroup, and three additional beetles as more distant outgroups. Under both Bayesian inference (BI) and maximum likelihood inference (MLI), the major taxa within Staphyliniformia are each monophyletic: (i) Staphylinoidea, (ii) Hydrophiloidea s.l., and the contained superfamilies (iii) Hydrophiloidea s.s. and (iv) Histeroidea, although Staphylinoidea and Hydrophiloidea s.l. are not strongly supported by MLI bootstrap. Scarabaeiformia is monophyletic under both methods of phylogenetic inference. However, the relative relationships of Staphylinoidea, Hydrophiloidea s.l. and Scarabaeiformia differ between BI and MLI: under BI, Staphyliniformia and Scarabaeiformia were sister groups; under MLI, Hydrophiloidea s.l. and Scarabaeiformia were sister groups and these together were sister to Staphylinoidea. The internal relationships in Scarabaeiformia were similar under both methods of phylogenetic inference, with Cetoniinae, Dynastinae+Rutelinae, Hybosoridae, Passalidae, Scarabaeidae and Scarabaeinae recovered as monophyla. Histeridae comprised two major clades: (1) Abraeinae, Trypanaeine and Trypeticinae; and (2) Chlamydopsinae, Dendrophilinae, Haeteriinae, Histerinae, Onthophilinae, Saprininae and Tribalinae. The relationships among early-divergent Hydrophiloidea differed between BI and MLI, and overall were unresolved or received only moderate to low nodal support. The staphylinoid families Agyrtidae, Hydraenidae and Ptiliidae were recovered as monophyletic; the latter two were sister taxa, and Staphylinidae+Silphidae was also monophyletic. Silphidae was placed within Staphylinidae in close relation to a subset of Tachyporinae. Pselaphinae and Scydmaeninae were both recovered within Staphylinidae, in accordance with recent analyses of morphological characters, although not always with recently proposed sister taxa. None of the four major groups of Staphylinidae proposed by Lawrence and Newton (1982) was recovered as monophyletic. Certain highly specialized staphyliniform habits and morphologies, such as abdominal defensive glands and reduced elytra, have arisen in parallel in separate lineages. Further, our analyses support two major transitions to an aquatic lifestyle within Staphyliniformia: once within Staphylinoidea (Hydraenidae), and once within Hydrophiloidea s.l. (Hydrophiloidea s.s.). On a smaller scale, the most common transition is from litter to subcortical or to periaquatic microhabitats and the next most common is from litter to carrion and to fungi. Overall, transitions to periaquatic microhabitats were the most numerous. The broad picture in Staphyliniformia seems to be a high level of evolutionary plasticity, with multiple possible pathways to and from many microhabitat associations, and litter as a major source microhabitat for diversification. In Scarabaeiformia, the most common transitions were from litter to foliage, with flowers to litter, litter to flowers, and litter to dung being next, and then litter to roots, logs or carrion. Litter is again the largest overall source microhabitat. The most common transitions were to foliage and flowers.It thus seems that the litter environment presents ecological and evolutionary opportunities/challenges that facilitate entry of Staphyliniformia and Scarabaeiformia into new' and different ecological adaptive zones.