Jiang Wei fled to Shanggui, intending to surrender to Liang Qian. Just as Liang Qian was about to welcome him, he was killed by Wei Yan's ambush. Jiang Wei was greatly alarmed and hurriedly rushed to Jicheng, intending to surrender to Yin Shang. Yin Shang was also killed by Zhang Yi in a surprise attack. Jiang Wei had no way out and was surrounded on all sides by Shu soldiers.
At the moment when Jiang Wei was at a dead end, he suddenly saw a rider breaking through the encirclement—it was Kongming. Kongming said with a smile, 'Boyue, I sent people to invite you several times—why did you not come?' Jiang Wei reined in his horse, feeling deeply ashamed, and said, 'I was but a subordinate under Ma Zun. I am grateful that the Chancellor did not abandon me and wished to recruit me, but unfortunately I failed to recognize the times early enough, leading to today's predicament.'
Kongming said, 'I know you are loyal and filial, so I cannot bear to harm you, nor to trap you with schemes. Now that things have come to this, Boyue, why not leave the darkness and come to the light, to jointly support the Han dynasty?' Jiang Wei Moved by Kongming's kindness in recognizing his talent, he dismounted and bowed, saying, 'I am originally a minister of the Han, but helplessly found myself in Wei's camp. Now that I have met the Chancellor, I am willing to exert all my strength to repay this recognition!' Kongming was overjoyed. He personally untied his bonds and took him by the hand into the tent.
Kongming said to the assembled generals, 'Having obtained Boyue is like adding wings to a tiger!' He then appointed Jiang Wei as a General of the Household, to assist in military strategy, and personally taught him the art of war, saying, 'All that I have learned in my life is here—Boyue, you must make good use of it.' Jiang Wei wept with gratitude. From then on, he wholeheartedly assisted Kongming in his efforts to restore the Han dynasty.
Now, when Cao Zhen learned that he had lost three commanderies and also Jiang Wei, he was greatly alarmed and urgently reported it to Wei ruler Cao Rui. Cao Rui was furious and ordered Cao Zhen and others to hold the passes steadfastly and not engage in reckless battle with Shu forces.
Kongming intended to take Jieting as the throat to advance on Chang'an. Ma Su volunteered to defend Jieting and signed a military pledge, saying, 'The Chancellor has thoroughly studied military books, and I too am well-versed in military strategy—I am willing to defend Jieting to the death!' Kongming highly valued his talent and thus agreed, appointing Wang Ping as his deputy, and cautioned him: 'Though Jieting is small, it bears great importance. You should set up camp on level ground and not act rashly.'