The main army arrived at Dingjun Mountain. Huang Zhong could see that the mountain was steep and dangerous, making it difficult to capture quickly. Fa Zheng said, "We should first occupy the terrain and block the key pass. If they come out recklessly, we can attack them." Following the plan, they set up camp at the foot of Dingjun Mountain, nestled against the mountain and beside the river, and sent soldiers daily to challenge the enemy. Xiahou Yuan, relying on his bravery, wanted to go out and fight, but was dissuaded by Zhang He. After a few days, Huang Zhong feigned a retreat to lure Xiahou Yuan out of camp for pursuit. Xiahou Yuan fell into the trap and led his troops in hot pursuit. Unexpectedly, Huang Zhong had set up an ambush halfway, devastating Xiahou Yuan's forces and driving them back to Dingjun Mountain. Huang Zhong's morale soared, and he pursued the victory straight to the foot of the mountain.
Fa Zheng climbed to a high vantage point and observed that Xiahou Yuan's troops were demoralized. Noting Xiahou Yuan's impatience, he predicted that Xiahou Yuan would personally come out to oversee the battle. He then said to Huang Zhong, "Now we should conserve our strength and wait until they are exhausted before launching an attack. I observe that Xiahou Yuan will definitely come out personally tomorrow to repair the deer antlers [defensive barriers]. General can take advantage of his unpreparedness and strike swiftly!" Following his advice, Huang Zhong held his troops still and waited for the next day. The next day, Xiahou Yuan indeed came out personally to supervise the repair of the deer antlers. Seeing this from afar, Fa Zheng immediately ordered Huang Zhong to attack.
At the sound of the drum, Huang Zhong, full of spirit and vigor, charged forward on his horse with a single blade. Before Xiahou Yuan could brace himself, Huang Zhong let out a furious shout, and with a flash of his blade, cleaved him in two. Thus Dingjun Mountain was taken by Huang Zhong. Upon hearing of Xiahou Yuan's death, Cao Cao was furious and personally led a large army to seize Hanzhong. Liu Bei and Zhuge Liang stood in strict defensive formation. Cao Cao's repeated attacks failed, compounded by dwindling supplies, exhausted troops, and wavering morale. Moreover, Yang Xiu was executed by Cao Cao for having seen through the meaning of the phrase "chicken ribs." In the end, Cao Cao found himself in a dilemma and had to lead his troops back to Chang'an. Thus Liu Bei gained complete control of Hanzhong, proclaimed himself King of Hanzhong, established his administration, appointed officials, and enfeoffed the Five Tiger Generals, shaking the realm with his prestige for a time.