In 625, Eastern Tujue attacked Taiyuan, and Li Jing led some of his troops north to resist Eastern Tujue. It was said that all of the other Tang generals were defeated by Eastern Tujue forces, but Li Jing was able to preserve his troops. In 626, when Eastern Tujue attacked again, Li Jing was made the commandant at Ling Prefecture (靈州, roughly modern Yinchuan, Ningxia), and he tried to cut off Eastern Tujue's return path, although soon Tang and Eastern Tujue made peace. It was said that at this time that Li Shimin, then engaged in an intense rivalry with his older brother Li Jiancheng the Crown Prince and fearing that Li Jiancheng might be intending to kill him, solicited advice from Li Jing and Li Shiji, and both refused to speak on the matter, drawing respect from Li Shimin for their unwillingness to be involved in an internecine struggle. In 626, Li Shimin set a show down for Li Jiancheng and another brother, Li Yuanji the Prince of Qi at Xuanwu Gate, killing them, and then effectively forced Emperor Gaozu to create him crown prince and then pass the throne to him (as Emperor Taizong).