The uncontrollable growth of Li dendrites and large volume change during cycling limit the practical applications of Li metal anodes. Herein, the in situ-formed Pd nanoparticles locked in three-dimensional N-doped microporous carbon (Pd/NMC), which are derived from the catalyst for Buchwald–Hartwig (B–H) coupling polymerization, have been constructed to address these issues. The homogeneously distributed Pd nanoparticles effectively reduce the overpotential of Li nucleation through the reversible Li–Pd alloying reaction and boost Li+ diffusion by reducing the migration barrier. Furthermore, the Pd nanoparticles guide the Li selective nucleation and uniform growth in the 3D N-doped microporous carbon. Meanwhile, the spatial confinement effect alleviates the volume changes. As a result, the stable and reversible Li metal anode exhibits a high Coulombic efficiency of 98.7% over 1000 cycles at 1 mA cm–2. Full cells with LiFePO4 (LFP) as the cathode deliver a long lifespan of 600 cycles with 0.02% capacity decay per cycle at 2 C. This work provides a new polymerization–carbonization strategy to prepare a lithiophilic host for energy-dense Li metal batteries.