Metal-doped mesoporous composites were synthesised by using a facile one-pot sol–gel approach. Special multifunctional surfactants were designed and used simultaneously as structure-directing agents, N-doped carbon source and metal dopant. This versatile profile of properties is obtained by combining complex metallate anions carrying dicyanamide ions as ligands with nitrogen-containing amphiphilic counteranions. Furthermore, also the use of nonamphiphilic countercations yields interesting precursors that can be converted into carbon materials with submicron-sized morphologies by simple annealing. We therefore present herein a novel precursor system enabling immediate pathways to new materials that are of significant interest for sustainable catalysis and energy applications.