Owing to the unique structure and physicochemical properties, including high specific surface area, self-doped N atoms, open pore structure and good chemical stability, zeolitic imidazolate frameworks (ZIFs) and their derivatives have been widely used in the field of energy storage. Here, a new type of "cocoon"-like Zn/N doped ZIF-derived porous carbon (Zn@N-C-800) is synthesized as an anode for lithium-ion batteries (LIBs) and sodium ion batteries (SIBs) through a one-step carbonization process using a novel Zn-ZIF as the precursor. In Zn@N-C-800, the "cocoon"-like disordered carbon skeleton is conducive to electrolyte infiltration, while the Zn/N doping can provide additional active sites for ion storage. Benefiting from these unique structural characteristics, Zn@N-C-800 achieves excellent electrochemical performances as anode for both LIBs and SIBs: an ultrahigh rate capability of 352 mAh g−1 can be delivered at 12.8 A g−1 for LIBs; an outstanding long-term cycling stability (312 mAh g−1 at 1 A g−1 after 2000 cycles) can be achieved for SIBs. This paper provides new ideas for the design and preparation of high-performance anodes for LIBs and SIBs.