Dinesh Chandimal (65) and Kumar Sangakkara (74 not out) shared an 88-run second-wicket partnership as Sri Lanka finished on 195-4 having been set a 270-run victory target earlier in the day by Pakistan, seeking a draw to level the three-match series.
Hosts Sri Lanka, who won the first Test in Galle by 209 runs while the second Test in Colombo was drawn, recorded their first series victory for almost three years when they beat New Zealand. Since then they have drawn three series and lost five.
The defeat was Pakistan's first since England beat them 3-1 in August 2010 and captain Misbah-ul-Haq's first series loss since his appointment two months later.
Sri Lanka began the chase on a positive note with openers Tharanga Paranavitana and Chandimal posting 44 for the first wicket.
The momentum was continued by Chandimal and Sangakkara but off-spinner Saeed Ajmal halted the Sri Lankan run chase when he took three key wickets.
Chandimal was out for 65 in the final over before tea then Mahela Jayawardene (11) and Thilan Samaraweera (10) followed before Sri Lanka batted the remainder of the match in cautious fashion.
"Our mindset was to win but going into the last session against a quality team like Pakistan we probably thought it was not worth it," Sri Lanka captain Jayawardene told reporters.
"They set a very negative field to cramp our guys and we thought let's not take too many risks at the end because we are 1-up in the series."
Jayawardene's counterpart Misbah expressed surprise the hosts gave up their pursuit of the victory target.
"Chasing 270 in 71 overs is not an easy task but after the start being 150-2 and when you need less than four an over that was the time they could have taken the game away from us," the 38-year-old said.
"I was really surprised they put the shutters up and never tried to go for the runs. I don't know what happened the way the wicket was behaving, scoring was really easy on it, they could have gone for the target."
One of the batsmen at the crease at the end, Sangakkara, was named man of the series for scoring 490 runs (average 163) while Asad Shafiq was awarded the match award for his defiant unbeaten century that saved Pakistan from certain defeat.
Shafiq (100 not out) hit his second Test hundred as Pakistan declared their second innings at 380 for eight wickets.
The visitors batted for 100 minutes on the fifth and final day, allowing Shafiq to get his century before their attempt to salvage something from the series.
Resuming on 299 for eight, Pakistan's ninth wicket pair of Shafiq and Adnan Akmal (35 not out) shared an unbroken 81-run partnership on a benign pitch.
Shafiq showed a lot of maturity and reached his hundred with a single to square leg off Rangana Herath before the declaration came.
Shafiq batted for 195 balls and hit nine fours in his chanceless innings.
Akmal, batting with a hairline fracture on his left-hand, was no less impressive in his 96-ball gritty knock.
Herath was Sri Lanka's best bowler, ending with figures of four for 99, while Dilhara Fernando took three for 74.