桓玄
In 391, during the reign of Emperor Xiaowu, Pei became a Palace General (殿中將軍) at the age of 20. In 398, during the reign of Emperor An, Pei's uncle, Yu Kai (庾楷), who was the Governor of Yu Province, allied with Wang Gong (王恭), the Governor of Yan and Qing provinces, to attack the imperial capital, Jiankang. They were defeated. Yu Kai fled to join the warlord Huan Xuan, after which he nominated Pei to be the Administrator of Xinye, but Pei considered the dangers of joining his uncle and refused to move there. War broke out between the warlords later and Yu Kai was killed by Huan Xuan. Pei survived because he did not join Yu Kai.