Afghanistan collapsed to 97 for seven in pursuit of a modest target of 211 and were all but out of this Pool A clash at University Oval.
But for the second time in as many days, following Ireland's nailbiting win over the United Arab Emirates on Wednesday, two non-Test nations produced a dramatic climax to a World Cup match.
Shenwari turned this contest on its head with a 147-ball innings featuring seven fours and five sixes.
However, the last-wicket duo of Hamid Hassan (15 not out) and Shapoor Zadran (12 not out) held their nerve, with Shapoor looking anything but a No 11 as he struck the winning boundary off Iain Wardlaw three balls into the last over.
Also Read
"It was difficult because we lost early wickets but I did my job," said man-of-the-match Shenwari.
After he was out, Shenwari could be seen sitting with his head in his hands, seemingly in despair at costing Afghanistan the match.
Afghanistan captain Mohammmad Nabi thought his side had thrown away their chance with the bat after restricting Scotland to 210 all out in an innings where left-arm paceman Shapoor took an impressive four for 38 in his maximum permitted 10 overs.
"The pressure was extreme again but Shenwari batted brilliantly," said Nabi. "It's good to put two points on the board. This is our first win in the World Cup and everyone (in Afghanistan) will enjoy this."
"It's never easy losing a game but this is a particularly difficult one for us to swallow," said Scotland captain Preston Mommsen, whose side have now lost all three of their pool matches following defeats by New Zealand and England.
"We had them seven down but couldn't finish them off. It just wasn't to be.