Ordered mesoporous carbon (CMK3) before and after doping with nitrogen (N) are prepared successfully by a nanocasting method using sucrose as carbon source, and urea (or melamine) as nitrogen source. After doping N, the materials show an increase in the specific surface area and a slight decrease in the porosity. The N content of the N-doped CMK3 obtained from melamine precursor (CMK3-M) is 5.82 at.%, approximately 4 times as high as that of the N-doped CMK3 obtained from urea precursor (CMK3-U). Among three resultant samples, the CMK3-M exhibits the highest lithium storage capability. Owing to possessing the high N content the CMK3-M can deliver a reversible capacity of 812.7 mAh/g at a current density of 100 mA/g. After 50 cycles of the charge-discharge, the CMK3-M deliveries the capacity of 652.06 mAh/g, maintaining 80.2% of its initial reversible capacity with a high coulombic efficiency of 99.5%.