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 with 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.
Sri Lanka captain Dinesh Chandimal was excited at holding on to the number one ranking.
“We are over the moon,” said Chandimal.
“We keep our number one ranking. Kusal and Dilshan (Tillakaratne, wo made 48) batted really well. After that Seekkuge (Prasanna) and (Kumar) Sangakkara batted well at the end so it was a good total.”
Pakistan captain Mohammed Hafeez admitted they conceded too many runs.
“We didn’t bowl in the right areas early on, and they got a score higher than what we expected. We were looking at 160-170,” said Hafeez.
Perera had been ably supported by 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 chipped in with a rapid 13-ball 28 with two sixes and two fours.
Earlier Perera, who hit five fours and four sixes, put on a rapid 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.
Perera was run out off the last delivery, improving his previous highest Twenty20 score of 64 he made against Bangladesh at Pallekele earlier this year.
The previous highest T20 total against Pakistan was 191, made twice by Australia.
The two teams now play five one-day internationals, with the first game in Sharjah on Wednesday. They will also play three Tests.