The invention relates to a method for preparing Ni@C or Co@C core-shell nanoparticles. The method comprises the steps: (1) adding nickel chloride or cobalt chloride into an isopropanol aqueous solution, adding nitrilotriacetic acid, and stirring for 1 hour at room temperature, so as to obtain a mixed solution; (2) transferring the mixed solution to a reactor, placing the reactor into an air-blasting drying oven, carrying out heat preservation for 6 hours at the temperature of 180 DEG C, cooling, then, separating a product, cleaning and drying in vacuum, so as to obtain a precursor; (3) putting the precursor into a tubular furnace, heating to the temperature of 500-600 DEG C at the heating rate of 2 DEG C / min, and carrying out heat preservation for 2 hours, thereby obtaining a black product, namely the Ni@C or Co@C core-shell nanoparticles. The method has the advantages that the method is simple in process, low in energy consumption, low in cost and free from environmental pollution, and the in-situ synthesis of the Ni@C or Co@C core-shell nanoparticles is realized; the prepared core-shell nanoparticles have porous structures and are larger in specific surface area and narrower in pore size distribution, thereby being a promising catalyst or energy storage material.