Afghanistan 273 (Stanikzai 51, Nabi 51, Roland-Jones 6-73) and 18 for 3 need another 199 runs to beat England Lions 279 (Westley 84, Foakes 70, Alsop 40, Rashid Khan 4-48) and 210 (Foakes 89*, Gubbins 53, Rashid 8-74)
Ben Foakes passed another searching examination from Afghanistan's exciting legspin talent, Rashid Khan, to set up a fascinating fourth-day finish in Abu Dhabi.
Foakes, who had made 70 in the first innings, followed up with a patient and skilful unbeaten 89 second time around, compiled from 154 balls in 222 minutes.
The Surrey wicketkeeper shared partnerships of 66 with Middlesex opener Nick Gubbins, who was fifth out after grafting to 53 from 152 balls, and 51 with the Lions captain Toby Roland-Jones.
But there was no denying Rashid top billing in front of a small but highly enthusiastic crowd of Afghanistan supporters at the Zayed Cricket Stadium.
He had made quite an impression with 4 for 48 in the first innings but proved even more of a handful in the second, ending with 8 for 74 from 35 overs - giving him astonishing match figures of 12 for 122 on his first-class debut.
Lalchand Rajput, Afghanistan's experienced Indian coach, revealed afterwards that Rashid had only played T20 and 50-over cricket since playing in the ICC Under-19 World Cup in Bangladesh earlier this year.
"I think he has bowled superbly in this game," said Rajput. "He came from the under-19s and he was playing a lot of one-day cricket and T20 - this is the first four-day game he has played, and he has really done well. That shows that he's ready for all formats. We picked him because sometimes the wrist spinners you just get naturally - he is one of those."
The Lions were all out for 210 in their second innings, leaving Afghanistan needing 217 to win - and Tom Curran struck a huge double blow in his first over, pinning Javed Ahmadi lbw then having Rahmat Shah snapped up by Ollie Rayner at second slip in the space of three balls.
Curran's younger brother Sam chipped in with the wicket of Afsar Zazai, lbw to his second ball, and the Afghans closed on 18 for 3 - needing another 199 to win.
The day had started with Roland-Jones taking less than an over to collect the last wicket of Afghanistan's first innings, completing figures of 6 for 73.
The Lions lost Tom Alsop in the fifth over of their second innings, edging to second slip where Rahmat claimed a low catch.
But Tom Westley, who had top-scored with 84 in the Lions' first innings, started well again and shared a stand of 44 with Gubbins until he was lbw to Rashid's googly.
Joe Clarke was bowled by Rashid for the second time in the match four overs later, and the legspinner then switched ends to have Liam Livingstone lbw sweeping and leave the Lions tottering on 68 for 4.
Foakes joined Gubbins to steady the ship and the pair batted deep into the afternoon session until another flurry of wickets before tea.
They all went to Rashid - Gubbins adjudged caught behind off the bottom edge, Sam Curran edging the next ball, and Tom lbw to another googly, although in his case on the front foot.
At 152 for 7, the Lions were only 158 ahead, and seemingly short of a defendable total. So the 51 runs added by Roland-Jones and Foakes were precious, although the last three wickets tumbled quickly as Roland-Jones was yorked by the young Afghan seamer Karim Janat, Rayner was given caught behind off Rashid, and finally Jack Leach popped a catch to short leg.
Foakes ran out of partners after hitting nine fours and a six, but the late treble from the Curran brothers left the game finely balanced going into the last day.