In 215, Ma Chao defected to the warlord Liu Bei and aided him in seizing control of Yi Province (covering present-day Sichuan and Chongqing) from its provincial governor, Liu Zhang. Pang De remained in Hanzhong with Zhang Lu. Later that year, Cao Cao led his forces to attack Hanzhong and defeated Zhang Lu at the Battle of Yangping. Pang De joined Zhang Lu in surrendering to Cao Cao. As Cao Cao had heard of Pang De's valour, he immediately recruited Pang De as his subordinate and appointed him as General Who Establishes Righteousness (). Pang De was also enfeoffed as the Marquis of Guanmen Village () and given 300 taxable households to form his marquisate.