sparked a dramatic collapse, with Mohammed Nabi gone two balls later followed by a first-ball duck for Afsar Zazai.
It could have been worse for Afghanistan, with Shenwari dropped on 20 by Majid Haq in the slips.
Haq soon made amends for his mistake, catching Najibullah Zadran and Gulbadin Naib in quick succession to leave Afghanistan teetering on 97 for seven.
But Shenwari made the most of his reprieve and kept the innings alive, working with the tail to patiently graft a Test-like innings of 96 from 147 balls.
When he finally decided to unload, Shenwari plundered three sixes off a single Haq over but was caught on the boundary going for a fourth. That left Afghanistan needing 19 off 19 balls from the unlikely pair of Shapoor and Hamid Hassan.
Shapoor capitalised after Richie Berrington delivered a wide in the penultimate over, hitting a boundary off the extra delivery.
The paceman, who had only struck five boundaries in 32 previous ODIs, then managed to clip Wardlaw’s third delivery of the last over through the leg side to secure the most famous victory in Afghanistan’s short cricketing history.
Score Board
Afghanistan won toss
Scotland
K J Coetzer b Dawlat 25
C S MacLeod c Najibullah b Dawlat 0
H J W Gardiner lbw b Hamid 5
M W Machan b Nabi 31
*P L Mommsen c Afsar b Gulbadin 23
R D Berrington c Afsar b Dawlat 25
†M H Cross c Afsar b Shapoor 15
J H Davey c Hamid b Shapoor 1
R M Haq c Gulbadin b Shapoor 31
A C Evans c Nabi b Shapoor 28
I Wardlaw not out 1
Extras (lb 12, w 12, nb 1) 25
Total (all out; 50 overs) 210
Fall: 1-7, 2-38, 3-40, 4-93, 5-95, 6-132, 7-134, 8-144, 9-206, 10-210
Bowling: Shapoor 10-1-38-4 (1nb, 2w); Dawlat 10-1-29-3 (2w); Hamid 10-1-32-1; Gulbadin 9-0-53-1 (2w); Nabi 10-0-38-1 (2w); Javed 1-0-8-0
Afghanistan
Javed c Machan b Berrington 51
Nawroz b Evans 7
Asghar c Cross b Evans 4
Samiullah c Davey b Haq 96
*M Nabi lbw b Davey 1
†Afsar lbw b Berrington 0
Najibullah c Haq b Berrington 4
Gulbadin c Haq b Davey 0
Dawlat c Mommsen b Berrington 9
Hamid not out 15
Shapoor not out 12
Extras (lb 1, w 10, nb 1) 12
Total (9 wickets; 49.3 overs) 211
Fall: 1-42, 2-46, 3-85, 4-88, 5-89, 6-96, 7-97, 8-132, 9-192
Bowling: Wardlaw 9.3-0-61-0 (1nb, 2w); Davey 10-1-34-2 (1w); Evans 10-1-30-2 (4w); Haq 10-0-45-1 (1w); Berrington 10-0-40-4 (2w)
Result: Afghanistan won by 1 wicket
Points: Afghanistan 2, Scotland 0
Man of the Match: Samiullah Shenwari (Afghanistan)
Umpires: S D Fry (Australia) and R S A Palliyaguruge (Sri Lanka). TV umpire: R J Tucker (Australia). Match referee: D C Boon (Australia)