Nano- and micro-composites comprised of porous carbon and magnetic particles are prepared by one-step pyrolysis of metal-organic frameworks (MOFs). The porosity and composition of resulting magnetic porous carbons are facilely regulated by altering the pyrolysis temperature and changing the organic building blocks incorporated within the initial MOFs.