Bismuth oxyfluoride impregnated CMK-3 nanocomposite is synthesized by a facile nanocasting approach. Mesoporous carbon CMK-3 can suppress the aggregation and growth of bismuth oxyfluoride particles and offer rapid electron and Li ion passageways. Bismuth oxyfluoride nanoparticles are embedded in the mesoporous channels with particle size less than 20 nm. The bismuth oxyfluoride@CMK-3 nanocomposite maintains 148 mA h g−1 after 40 cycles with the capacity from both the bismuth oxyfluoride and the functional groups on the mesoporous carbon. The hybrid with confined bismuth oxyfluoride nanoparticles, conductive carbon network, and oxygen functional groups on the carbon matrix exhibits higher capacity and cycling stability than bulk bismuth oxyfluoride particles when used as lithium ion batteries cathode.