Afghanistan 314 (Rahmat 98, Asghar 67, Shahidi 61, Thompson 3-28) and 29 for 1 (Ihsanullah 16*, Rahmat 11*) need 118 more to beat Ireland 172 (Murtagh 54*, Nabi 3-36, Ahmadzai 3-41) and 288 (Balbirnie 82, O'Brien 56, Rashid 5-82, Ahmadzai 3-52)
Dehradun: Spinner Rashid Khan claimed five wickets to put Afghanistan in sight of their maiden Test victory after bowling out Ireland for 288 on day three of the one-off game on Sunday.
Chasing 147 to win, Afghanistan were 29 for one at stumps. Ihsanullah Janat, on 16, and Rahmat Shah, on 11, were batting at close of play in Dehradun.
Spinner Andy McBrine had opener Mohammad Shahzad caught behind for two before Janat and Shah, who made 98 in Afghanistan's first innings total of 314, played out the last few overs of the day.
Ireland batsmen Andy Balbirnie and Kevin O'Brien had earlier hit half-centuries before Khan returned career-best figures of 5-82 to bowl out Ireland in the final session of play.
Balbirnie made 82 and O'Brien 56 before a 10th-wicket 58-run partnership between James Cameron-Dow and Tim Murtagh set up a potentially tricky chase for the Afghans.
Cameron-Dow was left unbeaten on 32 after number 11 Murtagh, who hit 54 not out in Ireland's first innings score of 172, was the last man out on 27.
Earlier Balbirnie put on 104 runs for the third wicket with James McCollum, who made 39, to frustrate the Afghanistan bowlers in the first session.
An umpiring howler cost Ireland their first wicket of the day with Paul Stirling adjudged lbw off paceman Yamin Ahmadzai for 14 after the opener got a thick edge onto his pad.
Balbirnie, who resumed the day on 14, stood firm to register his maiden Test half-century with a boundary off Mohammad Nabi.
Ireland took lunch at 124-2 but a batting collapse in the second session saw them slip to 157-6, with Khan and Salamkheil sharing the spoils.
Balbirnie was caught behind off Salamkheil after his 149-ball stay at the wicket, and Khan trapped McCollum lbw in the very next over as Afghanistan regained control.
O'Brien, who took Ireland past their 142-run trail and into a lead, then put on 63 runs with George Dockrell, who made 25, to take the attack to the opposition bowlers.
But Khan got the two dangermen back in the pavilion after tea to get into the Ireland tail that once again wagged.
The left-handed batting duo of Cameron-Dow and Murtagh put on another defiant stand for Ireland, who had posted an 87-run last-wicket partnership in their first innings.