Even after a decade or so of research, the direct synthesis of highly crystalline mesoporous transition-metal oxides that are thermally stable and well ordered still constitutes a major challenge. Although various soft- and hard-templating approaches have been developed in the past, they usually suffer from multiple, tedious steps and often result in poor structure control. For many applications including power generation and energy conversion, however, high crystallinity and controlled mesoporosity are a prerequisite. To this end, here we report on an approach established for group-IV (titanium) and group-V (niobium) oxides, with potential applications to photovoltaic cells and fuel cells, respectively, which overcomes previous limitations. It gives direct access to the desired materials in a 'one-pot' synthesis using block copolymers with an sp2-hybridized carbon-containing hydrophobic block as structure-directing agents which converts to a sturdy, amorphous carbon material under appropriate heating conditions. This in situ carbon is sufficient to act as a rigid support keeping the pores of the oxides intact while crystallizing at temperatures as high as 1,000 degrees C.