Emperor Wen died in 604, and Yang Hao's uncle
Yang Guang took the throne as
Emperor Yang. In 606, he created Yang Hao the Prince of Qin and Yang Zhan the Marquess of Jibei. By 613, Yang Hao was serving as the commander of the militia in Heyang Commandery (, roughly modern
Jiaozuo,
Henan) when the general
Yang Xuangan rebelled nearby. Emperor Yang, then at the front of a campaign against
Goguryeo, sent the general
Yuwen Shu back to Sui territory to attack Yang Xuangan, and Yuwen and Yang Hao exchanged letters, and they further met and joined forces against Yang Xuangan. However, after Yang Xuangan's rebellion was suppressed, Yang Hao was indicted for communicating with imperial officials—an act not allowed for imperial princes—and removed from his post. In spring 618, with the Sui state engulfed in various rebellions, Yang Hao was with Emperor Yang at Jiangdu (, in modern
Yangzhou,
Jiangsu), when a coup led by the general
Yuwen Huaji (Yuwen Shu's son) killed Emperor Yang. The coup leaders also killed many of Emperor Yang's relatives and high-level officials. However, as Yang Hao was friendly with Yuwen Huaji's brother Yuwen Zhiji (), Yuwen Zhiji persuaded Yuwen Huaji to spare Yang Hao, and subsequently, Yang Hao was declared emperor by an edict issued in the name of Emperor Yang's wife
Empress Xiao, although Yuwen Huaji wielded actual powers, as
regent. ==Reign==