In Friday's final, they will face Bangladesh, who eased past a disappointing Sri Lanka by five wickets to guarantee that the eventual champions will claim a first ever Asian Games gold medal.
Afghanistan scored 125-8 in their 20 overs before limiting Pakistan's flamboyant batsmen to just 103-7.
"It's a big win for Afghanistan. Every person there is watching the match and everybody is happy about this win," said captain Mohammad Nabi.
Afghanistan's score did not look enough as Pakistan made a lightning start to their reply, racing to 30 off just three overs.
Opening batsman Sharjeel Khan set the tone, hitting 12 off the first over bowled by Sahpur Zadran before he was lbw to Mirwais Ashraf for 23 off 16 balls with four boundaries and a six.
But Afghanistan managed to apply the brakes in mid-innings as wickets tumbled.
As tensions rose there was a fierce verbal exchange between Pakistan captain and opener Khalid Latif and Afghanistan wicketkeeper Mohammad Shahzad, which needed the intervention of the umpires.
Nabi then trapped Latif lbw for 26.
Naeemuddin Qazi was run out to leave Pakistan on 60-3 and two wickets in the same over by Karim Sadiq left them struggling at 68-5.
Naeem Anjum holed out as Pakistan tried in vain to find the boundaries that would ease the pressure and they failed to put themselves in a position to launch a final assault.
Pakistan skipper Latif said "abusive words" had been used against him but denied that it led to his dismissal soon afterwards.
He put the defeat down to costly mistakes including a number of missed run-outs.
"I knew Afghanistan's strengths because most of them play in Pakistan's domestic cricket but I was not expecting they would beat us because we started quickly," said Latif, who has played five one-day internationals.
Earlier, Afghanistan made a steady start to their innings through openers Sadiq (19) and Shahzad (17).
They reached 35 without loss but a flurry of wickets left them struggling on 55-4.
A partnership of 46 between Shabir Noori, who hit a quickfire 35 off 30 balls, and Asghar Stanikzai (10) gave impetus to the innings but wickets continued to fall at regular intervals.
Sri Lanka brought 11 internationals to Guangzhou, but after squeezing past minnows Nepal by just two wickets in the quarter-finals, they were comfortably defeated by Bangladesh.
Sri Lanka were all out for 101 with Mohammad Sohrawordi claiming 4-6 before Bangladesh eased to their target in the 16th over.
COMMENTS (11)
Comments are moderated and generally will be posted if they are on-topic and not abusive.
For more information, please see our Comments FAQ