On the sixth day, Kongming saw that the main lamp's flame was very bright and was overjoyed, believing that his life could be extended. But then Wei Yan rushed into the tent and reported, 'Wei troops are raiding the camp!' Impatient, Wei Yan ran straight to the lamp and stamped out the main lamp. Kongming threw down his sword and sighed, 'Life and death are fated; they cannot be averted by prayer!' Jiang Wei angrily rebuked Wei Yan and wanted to execute him. Kongming stopped him, saying, 'This is my destiny to die; it is not Wenchang's fault.'
Kongming, knowing he would not recover, summoned Yang Yi, Fei Yi, Jiang Wei and others into the tent and imparted his final plans. He instructed: 'After my death, you must not announce the mourning. You can make a large wooden figure, place my likeness inside it, and dress it with my clothes on a cart. When the Wei troops pursue, you can push it forward. In my entire life, I have never taken risks; Sima Yi will surely not dare to pursue.'
He also secretly taught Jiang Wei the twenty-four chapters of the Art of War, admonishing him, 'Do not do evil because it is small, nor neglect good because it is small.' He instructed Yang Yi on the retreat plan, saying, 'If Wei Yan shows rebellious intent, follow this plan and have Ma Dai execute him.' Yang Yi and the others wept, bowed, and accepted the orders. Kongming then gave final instructions; his words were faint as a thread, and he was on the verge of death. That night, heaven and earth mourned, the north wind howled, and on the Wuzhang Plains, a generation of wise chancellor finally passed away.
It was the twenty-third day of the eighth month in the twelfth year of Jianxing; he was fifty-four years old. After Kongming's death, Yang Yi followed his last orders, kept the funeral secret, and ordered Jiang Wei to lead the army forward, withdrawing slowly in formation. He also ordered Ma Dai and Wei Yan to be in the central army, while Yang Yi himself covered the rear. Wei Yan indeed refused to obey, presuming on his own merits, wanting to seize military command, saying, 'The Chancellor is dead; the Han dynasty is rightfully mine! Who dares to disobey my orders?'
Yang Yi sent someone to tell Wei Yan, 'If you do not retreat, we will report this to the Later Ruler.' Wei Yan angrily said, 'I am the vanguard; why should I retreat? You are all mere children; how dare you bully me?' Thereupon he led his own troops and counterattacked Yang Yi's army. Jiang Wei, Yang Yi and others followed Kongming's final plan and ordered Ma Dai to engage with him. Yang Yi also had a placard erected before Wei Yan's camp, reading: 'Anyone who dares to speak of rebellion shall be executed!'