A half-century from Angelo Mathews helped the Lions set a competitive target of 146 for victory and with Pakistan's middle order struggling in the run chase, Sri Lanka felt assured of claiming first blood in the series.
But Afridi came to the crease to score 39 runs from 20 balls, including five boundaries, and the veteran all-rounder would hit the winning six off the first delivery of the final over.
Sri Lanka reached 145 for five thanks to Mathews' well-taken 50 and some solid hitting from Dinesh Chandimal, who scored a neat 22 runs off 22 balls, including three fours.
Tillakaratne Dilshan was the first of two victims for Sohail Tanvir as he cut to point for just seven, and Thisara Perera managed a big six before going lbw off Saeed Ajmal for 15.
The in-touch Chandimal was then trapped by Afridi before he could do any serious damage.
Ajmal took his 400th international wicket in the 14th over, Kumar Sangakkara hitting directly to Afridi at short cover for 21 runs.
Mathews had announced himself with a six after replacing Chandimal and the 18th over proved particularly expensive for Pakistan as the Colombo-born batsman found the boundary three times.
A fourth four brought him his second T20 half-century but he was out next ball, Sharjeel Khan catching him at deep midwicket as he attempted a massive six off Tanvir.
Pakistan's quest for runs started well, Khan pushing Lasith Malinga to fine leg off the second delivery of the innings.
Sachithra Senanayake went for only four runs off Ahmed Shehzad but the first six of the Pakistani innings, off a Mathews lollipop, brought up a 50-run partnership between Mohammad Hafeez and Khan.
The wobble began in the 11th over as Perera saw Khan caught by Dilshan at long on for 34 and Ajantha Mendis took two wickets with consecutive deliveries in the next over.
Hafeez was first to go, departing lbw for 32, and Umar Akmal followed him back to the pavilion having been run out for five runs.
The dismissal of Umar Amin - for eight off Malinga - ushered Afridi into play and he set about knocking sixes into the stands to put Pakistan back in contention.
There was a nervous moment when Sohaib Maqsood fell lbw to Malinga for 13 but Bilawal Bhatti, who would depart for 10 thanks to Malinga, helped Afridi chip away at the dwindling target until just six runs were needed from the final over.
The 33-year-old former captain duly obliged, paddle-sweeping Kulasekara's delivery over the rope at fine leg.