In 211,
Zhong Yao suggested to the warlord
Cao Cao, who was the
de facto head of the Han central government, to launch an invasion of Hanzhong Commandery. Cao Cao heeded his advice and mobilised his forces. However, the warlords
Ma Chao and
Han Sui, who were based in the
Guanzhong region in between Cao Cao's territories and Hanzhong Commandery, thought that Cao Cao wanted to attack them so they started a revolt against the Han central government, leading to the
Battle of Tong Pass and subsequent battles. Although Cao Cao's forces emerged victorious against the Guanzhong warlords, they were in no condition to continue attacking Hanzhong Commandery so they retreated. Ma Chao escaped to Hanzhong Commandery after his defeat and pledged allegiance to Zhang Lu, who considered marrying his daughter to him. However, a subordinate of Zhang Lu's, Yang Bo (楊柏), said, "A man like that, who has no love for even his parents (referring to the execution of
Ma Teng caused by Ma Chao's rebellion), cannot love another" and the marriage proposal was scrapped. Ma Chao then borrowed soldiers from Zhang Lu and attempted to regain some of his lost territory from Cao Cao, but was ultimately unsuccessful. His failures caused the relationship between the two to sour. When
Liu Bei's forces had surrounded Liu Zhang, Ma Chao chose this time to leave Hanzhong Commandery with his own followers and join Liu Bei. Ma Chao's subordinate
Pang De, however, remained in Zhang Lu's service. In 215, Cao Cao again launched a campaign to conquer Hanzhong Commandery. Initially, Zhang Lu had no hope of standing against Cao Cao's armies, and planned to surrender. His younger brother Zhang Wei (), however, insisted on fighting and lead his army against the invading forces. He was soon killed in battle, and again Zhang Lu considered surrendering. His adviser Yan Pu told him that if they surrendered so easily, they would have no position to negotiate from. Instead, Zhang Lu retreated to his fortress at Bazhong (). When leaving his capital, he did not destroy his wealth and treasures, nor attempt to take them with him. Instead, Zhang left them behind, saying "These things belong to the country, not to me." Cao Cao was greatly impressed by this, and sent a messenger to Zhang Lu asking him to surrender. Yan Pu's plan was successful, as Zhang Lu and his forces were warmly welcomed by Cao Cao. Cao Cao appointed Zhang Lu as General who Guards the South () and enfeoffed his five sons as marquises. Zhang Lu also married his daughter to
Cao Yu, one of Cao Cao's sons. When Cao Cao turned Ma Chao's son Ma Qiu () over to Zhang Lu, Zhang Lu personally killed Ma Qiu – most likely as revenge against Ma Chao's desertion. Zhang Lu died in 216 and was honoured with the
posthumous title "Marquis Yuan" () by the Han imperial court. His sons continued to lead the "Five Pecks of Rice" Taoist Order, which later evolved into one of the two major Taoist schools that survive to modern times known as
Zhengyi Dao. ==In
Romance of the Three Kingdoms==