During Emperor Taizong's reign
In 626, Li Shimin, then locked in an intense rivalry with Li Jiancheng (who, as the older brother, was crown prince), feared that Li Jiancheng was about to kill him, and ambushed Li Jiancheng and Li Yuanji (who supported Li Jiancheng) at Xuanwu Gate and killed them. He then effectively forced Emperor Gaozu to create him crown prince and then yield the throne to him (as Emperor Taizong). Although Pei Ji appeared to have supported Li Jiancheng in the struggle, Emperor Taizong initially continued to honor him, and on one occasion, when Emperor Taizong was offering sacrifices to heaven outside the capital, he requested Pei and Zhangsun Wuji to ride with him in the imperial wagon, a great honor at the time.
In 629, however, when the Buddhist monk Faya (法雅) was accused to have spread false teachings (probably treasonous teachings) to the people and was executed, Pei was accused of having heard of the false teachings but not reported it, and therefore was removed from his honorific title of Sikong on 27 February and ordered to retire to his home in Pu Prefecture. When Pei requested to stay at Chang'an, Emperor Taizong rebuked him:
Duke, your contributions were not commensurate with your position; you only rose to this honored position due to your relationship with Taishang Huang [(i.e., Emperor Gaozu, now retired emperor)]. There were times during the reign of Wude [(武德, Emperor Gaozu's era name)] when the government was corrupt and poorly run, and it was your fault. Now I am allowing you to return to your home. Why do you complain?
Once Pei returned to Pu Prefecture, an insane man named Xin Xing (信行) stated to one of Pei's servants that he believed that Pei would be emperor. When Pei's servant reported this to the head servant, and the head servant in turn informed Pei, Pei, fearful, had Xin and the junior servant killed. Subsequently, the head servant embezzled money from Pei and feared punishment, and therefore reported the incident to Emperor Taizong. In anger, Emperor Taizong stated:
Pei Ji has four deadly crimes. One, even though he was one of the Three Excellencies, he associated with witches. Second, after he was removed from his post, he angrily stated that the empire rose only because of him. Third, he failed to disclose the wicked words. Four, he killed people to stop them from speaking. I have reasons to execute him.
Many people spoke on Pei's behalf, and Emperor Taizong did not execute him, but exiled him to Jing Prefecture (靜州, roughly modern Heishui county in Aba Prefecture, Sichuan - see Old Book of Tang Ch 45). At that time, the Qiang tribesmen in the region rebelled, and rumor arrived at Chang'an that they had taken Pei to be their leader. Emperor Taizong responded, "I have spared Pei, and he will surely not do this." Soon, news arrived that Pei had led his servants in defeating the Qiang. Emperor Taizong, remembering Pei's contributions, issued an order recalling him to the capital, but before he could do so, Pei died. Emperor Taizong granted him a number of posthumous honors, including the title of Duke of Hedong.