India, who had qualified for Fridays final, needed seven off the final over and one from the last two balls in the dead-rubber Super Four match.
But Ravindra Jadeja top-edged a pull off leg-spinner Rashid Khan to mid-wicket to fall for 25.
Mohammad Shahzad made 124 and Mohammad Nabi 64 in Afghanistans 252-8 as Jadeja took 3-46.
Pakistan face Bangladesh in Abu Dhabi on Wednesday to decide who will play India in the final in Dubai.
India players on the dressing room balcony celebrated what seemed a certain win after Jadeja hit the second ball of the final over for four.
But 20-year-old Rashid, who starred for Sussex in this summers T20 Blast, held his nerve to secure the 36th tie in one-day international history.
BBC