A functional composite as anode materials for lithium-ion batteries, which contains highly dispersed TiO2 nanocrystals in polyaniline matrix and well-defined mesopores, is fabricated by employing a novel one-step approach. The as-prepared mesoporous polyaniline/anatase TiO2 nanocomposite has a high specific surface area of 224m2 g−1 and a predominant pore size of 3.6nm. The electrochemical performance of the as-prepared composite as anode material is investigated by cyclic voltammograms and galvanostatic method. The results demonstrate that the polyaniline/anatase nanocomposite provides larger initial discharge capacity of 233mAhg−1 and good cycle stability at the high current density of 2000mAg−1. After 70th cycles, the discharge capacity is maintained at 140mAhg−1. The excellent electrochemical performance of the polyaniline/TiO2 nanocomposite is mainly attributed to its special structure. Furthermore, it is accessible to extend the novel strategy to other polymer/TiO2 composites, and the mesoporous polypyrrole/anatase TiO2 is also successfully fabricated.