In 604, Emperor Wen died—a death that traditional historians generally believed to be a murder ordered by Yang Guang, although they admitted a lack of direct evidence—and Yang Guang took the throne as Emperor Yang. He made Yuwen Huaji the deputy minister of husbandry. In 607, Emperor Yang visited Yulin Commandery (榆林, roughly modern Yulin, Shaanxi), and Yuwen Huaji and another brother, Yuwen Zhiji (宇文智及) engaged in forbidden trade with Tujue. Emperor Yang was incensed and ordered that they be executed, but at the last minute spared them, formally awarding them to their father Yuwen Shu as slaves.