Having reduced Australia to 76-3 soon after lunch, India's seam-heavy attack appeared to have put the 2021 runners-up in a position of strength at The Oval
Chasing a modest 263 for victory, Afghanistan's opening batsmen Mohammad Shahzad and Hazratullah Zazai got them off to a blistering start before Shahidi took charge to help them cross the finish line in the final over.
Pakistan batsman Babar Azam, who shone in their 4-0 series defeat by England this month, continued his excellent form with the bat ahead of the World Cup scoring 112 off 108 balls but his team were restricted to a below-par 262 in 47.5 overs.
Afghanistan spinners Mohammad Nabi (3-46) and Rashid Khan (2-27) then choked the Pakistan batsmen to lay the foundation for a famous win while pacer Dawlat Zadran claimed two wickets, including that of the dangerous Azam.