Zhang served as a military escort for Empress Dowager Cixi during the Boxer Uprising. He fought for the Qing at Nanjing in 1911, and then after the fall of the Qing, he remained loyal to Yuan Shikai. Despite serving as a general in the new Republic, he refused to cut his queue, as a symbol of his loyalty to the Qing. He was called the "Queue General". He seized Nanjing from the KMT in 1913, defeating the Second Revolution. Despite allowing his troops to savagely loot the city, Zhang was named a field marshal by Yuan. In 1917 Zhang entered Beijing to restore Puyi along with Kang Youwei but was thwarted by other generals. Zhang then took refuge in the Dutch legation and did not participate in politics again.