Jiang Wei fled to Shanggui, wishing to take refuge with Liang Qian. Just as Liang Qian was about to welcome him, he was ambushed and killed by Wei Yan's troops. Jiang Wei was greatly alarmed and hurried to Jicheng, wishing to take refuge with Yin Shang. Yin Shang was also ambushed and killed by Zhang Yi. With no way to escape, Jiang Wei was surrounded on all sides by Shu soldiers.
Just as Jiang Wei was at a dead end, he suddenly saw a rider charging into the encirclement — it was Kongming. Kongming laughed and said, 'Boyue, I sent men several times to invite you — why did you not come?' Jiang Wei reined in his horse, filled with shame, and said, 'I was but a man under Ma Zun's command. By the grace of the Chancellor, you wished to accept my surrender — unfortunately, I did not recognize the times early enough, leading to today's predicament.'
Kongming said, 'I know you are loyal and filial, so I could not bear to harm you, nor to scheme against you.' Now that matters have come to this, Boyue, why not abandon the darkness and come to the light, together restoring the Han dynasty?' Jiang Wei Moved by Kongming's kindness in recognizing his talent, he dismounted and bowed, saying, 'I was originally a subject of the Han, but helplessly found myself in Wei's camp. Now that I have met the Chancellor, I am willing to do my utmost, like a dog or a horse, to repay your kindness!' Kongming Greatly delighted, he personally untied Jiang Wei's bonds and took him by the hand into the tent.
Kongming said to the assembled generals, 'Gaining Boyue is like adding wings to a tiger!' He then appointed Jiang Wei as a Middle General, advisor in military strategy, and personally taught him the art of war, saying, 'All that I have learned in my life is here — Boyue should make good use of it.' Jiang Wei Wept with gratitude, and from then on devoted himself wholeheartedly to assisting Kongming, striving to restore the Han dynasty.
Now, when Cao Zhen heard that three commanderies were lost, and also that Jiang Wei was lost, he was greatly alarmed and urgently reported to the Wei ruler Cao Rui. Cao Rui was enraged and ordered Cao Zhen and others to defend the passes to the death, not to engage the Shu army recklessly.
Kongming wished to take Jieting, considering it the throat for advancing on Chang'an. Ma Su volunteered to defend Jieting and signed a military pledge, saying, 'The Chancellor has thoroughly studied military texts; I too know the art of war quite well and am willing to defend Jieting to the death!' Kongming Deeply impressed by his talent, he agreed, and appointed Wang Ping as his deputy, warning, 'Though Jieting is small, it is of great importance. You must set up camp on flat ground and do not venture out lightly.'