Wei Yan, enraged, led his troops to attack. Yang Yi sent someone holding the secret plan given by Kongming before his death and said to Wei Yan, 'The Chancellor left an order before his death: if I can shout three times ‘Who dares to kill me?’, you will become the commander.' Wei Yan laughed loudly and shouted three times: 'Who dares to kill me!' As soon as he finished speaking, Ma Dai suddenly caught up from behind and shouted, 'I dare to kill you!' Raising his blade, he struck and beheaded Wei Yan from his horse. When Wei Yan's soldiers saw this, they all scattered in defeat.
Meanwhile, Sima Yi, learning in his camp that the Shu army had withdrawn, was filled with doubt. Suddenly, a scout reported that the Shu army had erected a banner inscribed with 'Han Chancellor, Marquis of Wuxiang, Zhuge Liang.' Upon hearing this, Sima Yi was greatly alarmed and said, 'Kongming is not dead!' He hastily led his main army in pursuit. Chasing them to a hillside, he saw from a distance a four-wheeled carriage among the Shu formation; seated in it was a man holding a feather fan and wearing a silk cap, strikingly resembling Zhuge Liang.
Seeing this, Sima Yi believed Zhuge Liang was still with the army, deliberately setting up a deceptive array, and was thrown into confusion and uncertainty. Then he heard the Shu army loudly shout, 'The Chancellor is here! Sima Yi, why do you not come quickly?' Sima Yi was terrified, hastily turned his horse and fled, saying, 'If I do not leave, I will surely be captured by Kongming!' The Wei army also fell into chaos and retreated, trampling each other, with countless dead and wounded.
Seeing the Wei army withdraw, the Shu army proceeded slowly. After marching several tens of li, they learned that Sima Yi had realized it was an empty city and turned back to pursue. But the Shu army was already far away and could not be caught up. Later generations composed a poem in praise: 'Zhuge foresaw deeply, left a plan to repel Sima. The dead Zhuge could make the living Zhongda flee; who could not admire him?'
When Sima Yi caught up and saw the Shu army far off, he sighed, 'I am no match for Kongming! In life he could control me, and in death he could make me flee!' Thereupon he withdrew his troops and returned to camp. Under the command of Jiang Wei and Yang Yi, the Shu army followed the plans Zhuge Liang had laid out before his death, successfully retreating to Hanzhong and preserving the strength of Shu Han. Thus, the great Northern Expedition of Shu Han came to an end with the Chancellor's death, and the tripartite balance of power continued as before.