Younus Khan's epic unbeaten 171 guided Pakistan to their highest successful run chase, the tourists easing to a seven-wicket victory over Sri Lanka to clinch the three-match series by a 2-1 margin.
Skipper Misbah-ul-Haq (59 not out) blasted Jehan Mubarak for a six to seal Pakistan's first test series win in Sri Lanka since 2006 as the visitors chased down a daunting 377-run target in the second session of the final day.
Shan Masood (125) was the only Pakistani batsman to fall on Tuesday (local time), having added a remarkable 242 runs with Younus to turn the match on its head after Sri Lanka had seized control.
Shot out for 215 in the first innings and reeling at 13-2 in the second, Pakistan's stunning victory also saw them jump three places up to third in the test rankings.
Pakistan began the final day needing 147 for a memorable win and off-spinner Tharindu Kaushal drew Masood out of his crease with flight and turn to have him stumped.
The opener had earlier survived a strong caught-behind appeal when he was on 120 with bowler Angelo Mathews and wicketkeeper Dinesh Chandimal convinced he had edged it.
Umpire Ian Gould, however, deemed otherwise and Sri Lanka moved on having exhausted both of their review opportunities.
Younus continued to play with his characteristic fluency, however, and was unbeaten after registering his 11th 150-plus score in test cricket, the most by any batsman from his country.
The 37-year-old batted for more than seven hours in a man-of-the-match display, also becoming the first batsman to score five fourth innings centuries in test cricket.
Pakistani leg-spinner Yasir Shah, who claimed 24 wickets in three matches, won the man-of-the-series award.