The win also levelled the two-match series at 1-1 after Pakistan won the first match by three wickets on Wednesday.
Kusal Perera hit a career-best 59-ball 84 and spinner Sachitra Senanayake took three wickets in a match full of runs and records.
The series draw kept Sri Lanka at number one in the Twenty20 rankings, shattering Pakistan's hopes of claiming the top spot in any form of the game for the first time.
Chasing a daunting 212-run target, Pakistan finished at 187 in 19.2 overs with Sharjeel Khan scoring 50 and Sohail Tanvir making 41.
Perera had been ably supported by Tillakaratne Dilshan (48) and Kumar Sangakkara (44 not out) as Sri Lanka posted an imperious 211-3 in 20 overs.
Pakistan fought valiantly despite Sharjeel's 25-ball 50 but they slumped from 83-3 to 85-7 in the space of just seven balls.
They looked well set when Sharjeel brought up his fifty off just 24 balls with two towering sixes off Seekkuge Prasanna but was bowled by the leg-spinner in the same over.
Senanayake, who finished with 3-27, then chipped in with the wickets of Umar Amin and Bilawal Bhatti for nought in the same over.
Sohail Tanvir added 63 for the ninth wicket with Saeed Ajmal (20) -- the highest stand for this wicket in all T20 cricket -- but the target proved beyond Pakistan's reach.
Shahid Afridi scored a rapid 13-ball 28 with two sixes and two fours.
Earlier Perera, who hit five fours and four sixes, put on a quick 100 with fellow-opener Dilshan as Sri Lanka posted the highest ever total against Pakistan in all Twenty20 cricket.
Perera added another 77 for the third wicket with Kumar Sangakkara who made a 21-ball 44 not out with four boundaries and two sixes.
It was Dilshan who started the run spree, hitting four boundaries in the fifth over bowled by paceman Bilawal Bhatti as Sri Lanka raced to 90 off the first ten overs.
Dilshan hit eight boundaries before he holed out off spinner Saeed Ajmal.
Debutant Prasanna lifted the tempo with a blistering eight-ball 21 with the help of two boundaries and two sixes before he too fell to Ajmal, who despite the run-feast, finished with 2-25 in four overs.
Image: Kusal Perera celebrates his fifty
Photograph: Francois Nel/Getty Images
Afridi steers Pakistan to T20 win over Sri Lanka
ICC Awards: Clarke takes top honours; Pujara is emerging cricketer
De Villiers edges Kohli to go top in ODI rankings
Pakistan axe Malik, Razzaq for Sri Lanka series
Dhoni in ICC Test, ODI teams; Kohli misses out on ODI spot