Xia territory was temporarily taken over by Tang, but in fall 621, Liu Heita rose against Tang, declaring that he was avenging Dou (whom Emperor Gaozu had executed). Liu quickly captured most of former Xia territory, and when Liu approached the former Xia capital Ming Prefecture, Li Shiji, who was then at nearby Zongcheng (), abandoned Zongcheng and entered Ming to assist its defense, but despite that, Liu defeated him and captured Ming, seizing it as his capital and forcing Li Shiji to flee. Li Shiji subsequently served under Li Shimin in attacking Liu, who had by now declared himself the Prince of Handong, in spring 622, and in a battle, Li Shiji's officer Pan Mao () killed Liu's major general Gao Yaxian (), who had persuaded Liu to rise against Tang in the first place. Subsequently, when Liu attacked Li Shiji, Li Shimin tried to come to Li Shiji's aid but was surrounded and nearly captured, being saved only by the heroics of Yuchi Gong. Li Shimin subsequently defeated Liu by flooding Liu's troops with water from the Ming River (flowing through Ming Prefecture), and Liu fled to Eastern Tujue. (Liu would return later that year and again take over former Xia territory, before being decisively defeated by Li Shimin's older brother Li Jiancheng the Crown Prince.) Li Shiji subsequently followed Li Shimin in attacking Liu's ally Xu Yuanlang the Prince of Lu, who controlled the modern central and western Shandong), and after Li Shimin was recalled to Chang'an, he continued the campaign against Xu Yuanlang with Li Shentong and Ren Gui (). By spring 623, Xu was desperate and abandoned his capital Yan Prefecture, in modern Jining, Shandong), and he was killed in flight. Li Shiji took his head and sent it to Emperor Gaozu.