Abstract MXene with expanding interlayer and tunable terminations emerge as promising candidates for metal ion storage. Herein, we develop a facile urea decomposition strategy to obtain ultrathin nitrogen-modified Ti 3 C 2 T x (N-UT-Ti 3 C 2 T x ) with optimized terminations as anode for sodium/potassium ion storage. Experimental results have shown that NH 3 molecules produced by urea pyrolysis could introduce two types of nitrogen modifications in Ti 3 C 2 , function substitution for –OH (FS) and surface absorption on –O (SA). During subsequent hydrothermal and heating processes, the nitrogen atoms in situ substitute the lattice carbon in Ti 3 C 2 (LS). Further, the effects of these nitrogen modifications in Ti 3 C 2 on diffusion kinetics of Na + and K + are investigated by first-principles calculations. The superior Na + storage performances of the N-UT-Ti 3 C 2 T x anode are the main attribute of the nitrogen modification of LS in Ti 3 C 2 , while the excellent K + storage performances come from the synergistic effects of the nitrogen modifications of FS and LS in Ti 3 C 2 . This work emphasizes the effectiveness of surface engineering of nitrogen modifications and optimized terminations for improving the electrochemical performances of Ti 3 C 2 T x and inspires the design of heteroatom modified MXenes for energy storage.