A general and simple strategy is realized for the first time for the preparation of metal sulfide (MxSy) nanoparticles immobilized into N/S co‐doped carbon (NSC) through a one‐step pyrolysis method. The organic ligand 1,5‐naphthalenedisulfonic acid in the metal–organic framework (MOF) precursor is used as a sulfur source, and metal ions are sulfurized in situ to form MxSy nanoparticles, resulting in the formation of MxSy/NSC (M=Fe, Co, Cu, Ni, Mn, Zn) composites. Benefiting from the MxSy nanoparticles and conductive carbon, a synergistic effect of the composite is achieved. For instance, the composite of Fe7S8/NSC as an anode displays excellent long‐term cycling stability in lithium/sodium ion batteries. At 5 A g−1, large capacities of 645 mA h g−1 and 426.6 mA h g−1 can be retained after 1500 cycles for the lithium‐ion battery and after 1000 cycles for the sodium‐ion battery, respectively.