The Tang launched a counterattack in 864 under Gao Pian, a general who had made his reputation fighting the Türks and the Tanguts in the north. In September 865, Gao's 5,000 troops surprised a Nanzhao army of 50,000 while they were collecting rice from the villages and routed them. Gao captured large quantities of rice, which he used to feed his army. A jealous governor, Li Weizhou, accused Gao of stalling to meet the enemy, and reported him to the throne. The court sent another general named Wang Yanqian to replace Gao. In the meantime, Gao had been reinforced by 7,000 men who arrived overland under the command of Wei Zhongzai. In early 866, Gao's 12,000 men defeated a fresh Nanzhao army and chased them back to the mountains. He then laid siege to Songping but had to leave command due to the arrival of Li Weizhou and Wang Yanqian. He was later reinstated after sending his aid, Zeng Gun, to the capital and he returned with a reinstatement. Gao completed the retaking of Annan in fall 866, executing the enemy general, Duan Qiuqian, and beheading 30,000 of his men.
