Following the
An Lushan Rebellion, the
Tibetan Empire conquered the
Sha and
Gua prefectures of the Tang dynasty in 781.
Han population of the locality remained. By 851, the Tibetan Empire which had ruled the southern
Tarim Basin and modern Gansu region since 790 was being torn by civil war. Zhang Yichao's father, Zhang Qianyi, once held the post of commander-in-chief of the Sha Prefecture under the Tibetan Empire. In 848, Zhang secretly planned a rebellion with the other ethnic Han,
Yugur (Uyghur),
Tuyuhun and
Qiang residents of Sha Prefecture to return Sha Prefecture to Tang allegiance. One day, he led armed soldiers and approached the city gates, and the Han all rose in response. The Tibetan garrisons abandoned the city and fled. Zhang thereafter claimed the title of acting prefect of Sha Prefecture and submitted a petition to
Emperor Xuānzong of Tang, offering his loyalty and submission. Xuānzong thus made him Official Guard (防禦使,
Fangyushi) of Sha Prefecture. Later in the year, Zhang's launched an attack on ten other nearby prefectures with Tibetan garrisons—Gua (瓜州, in modern
Jiuquan,
Gansu); Yi (伊州, in modern
Hami Prefecture,
Xinjiang); Xi (西州, in modern
Turpan Prefecture,
Xinjiang); Gan (甘州, in modern
Zhangye,
Gansu); Su (肅州, in modern Jiuquan); Lan (蘭州, in modern
Lanzhou,
Gansu); Shan (鄯州, in modern
Haidong Prefecture,
Qinghai); He (河州, in modern
Linxia Hui Autonomous Prefecture,
Gansu); Min (岷州, in modern
Dingxi,
Gansu); and Kuo (廓州, in modern Haidong). Afterwards they prepared maps of the 11 prefectures and his brother Zhang Yize () submitted them to Xuānzong at
Chang'an to prove their allegiance to the Tang dynasty. Xuānzong named the 11 prefectures Guiyi Circuit (), with its capital at Sha Prefecture, and made Zhang Yichao its military commissioner and his secretary Cao Yijin () its secretary general. == As military governor of Guiyi ==