Lepidoptera (butterflies and moths) represent one of the most diverse animals groups. Yet, the phylogeny of advanced ditrysian Lepidoptera, accounting for about 99 per cent of lepidopteran species, has remained largely unresolved. We report a rigorous and comprehensive analysis of lepidopteran affinities. We performed phylogenetic analyses of 350 taxa representing nearly 90 per cent of lepidopteran families. We found Ditrysia to be a monophyletic taxon with the clade Tischerioidea + Palaephatoidea being the sister group of it. No support for the monophyly of the proposed major internested ditrysian clades, Apoditrysia, Obtectomera and Macrolepidoptera, was found as currently defined, but each of these is supported with some modification. The monophyly or near-monophyly of most previously identified lepidopteran superfamilies is reinforced, but several species-rich superfamilies were found to be para- or polyphyletic. Butterflies were found to be more closely related to 'microlepidopteran' groups of moths rather than the clade Macrolepidoptera, where they have traditionally been placed. There is support for the monophyly of Macrolepidoptera when butterflies and Calliduloidea are excluded. The data suggest that the generally short diverging nodes between major groupings in basal non-tineoid Ditrysia are owing to their rapid radiation, presumably in correlation with the radiation of flowering plants.