Near the end of the reign of Emperor Yang, Li Jing served as the Vice Prefect of Mayi Commandery (馬邑, roughly modern Shuozhou, Shanxi), when he served under the general Li Yuan the Duke of Tang, who was in charge of the nearby important city of Taiyuan (太原, in modern Taiyuan, Shanxi) against Eastern Tujue forces. Li Jing came to suspect that Li Yuan was plotting a rebellion, and therefore pretended to commit a crime and asked to be locked up and delivered to Emperor Yang, who was then at Jiangdu (江都, in modern Yangzhou, Jiangsu). However, he was first delivered to Chang'an, and then, as nearly the entire Sui state was engulfed in agrarian rebellions at that time, there was no way to deliver him to Jiangdu from there.