Sri Lanka 482 (Karunaratne 196, Yasir 6-184) and 96 (Wahab 4-41, Haris 3-1) beat Pakistan 262 (Azhar 59, Haris 56, Dilruwan 3-72, Herath 3-84) and 248 (Shafiq 112, Dilruwan 5-98) by 68 runs
Scorecard and ball-by-ball details
Like waves breaking upon a cliff, Sri Lanka's bowlers kept coming at Pakistan, until eventually, the hosts fractured and tumbled into the sea. So tantalisingly had the match been poised overnight, perhaps the ending was even a little anticlimactic. Sri Lanka's margin of victory was 68 runs - a comfortable win by most standards. Though Sarfraz Ahmed and Asad Shafiq had begun confidently, the visitors needed only 5.5 overs to break that partnership, and about 90 minutes in all to wipe out the lower half of the Pakistan innings. The series had been swept, completely unexpectedly, 2-0.
Dilruwan Perera was Sri Lanka's primary bowling figure on day five, as he had been throughout the innings, claiming two further wickets to complete a fourth career five-wicket haul. He also took that vital wicket of Sarfraz to break the mighty resistance Pakistan's sixth-wicket partnership had mounted.
Rangana Herath, who had had an uncharacteristically quiet fourth-innings until then, took two wickets of his own, and Suranga Lakmal had Shafiq caught at slip. After the battering Sri Lanka had received at home, at India's hands, this series victory must surely rank among the most surprising results of their Test history. On the Sri Lankan balcony, support staff were ecstatic, while on the field Dinesh Chandimal led elated celebrations. The joy was justified: not counting the win in a one-off Test against Zimbabwe, this was Sri Lanka's first Test series victory in almost a year.
Pakistan, meanwhile, have had a disappointing start to life post Misbah-ul-Haq and Younis Khan. Sarfraz and Shafiq needed to see out seven overs before the second new ball became available, but Sarfraz's wicket exposed the tail prematurely. That Shafiq progressed to an outstanding 11th Test hundred was almost forgotten in the final wash-up. He finished on 112 off 176 balls. The partnership with Sarfraz was worth 173. For the first time, Pakistan have lost a Test series since moving base to the UAE.
The previous four sessions of this match were practically dripping with drama, and day five also began with a little excitement. Shafiq glanced the second ball of the day to the fine leg fence to move into the 90s, before Sarfraz cracked a four behind point next over. Then, Sri Lanka had three near misses. Kaushal Silva swooped on the ball from point, but could not effect the direct hit that might have seen a diving Shafiq run-out for 95.
A few balls later, Sarfraz had dragged his back foot out of the crease while attempting a sweep, but wicketkeeper Niroshan Dickwella could not quite get the bails off in time. Finally, after Shafiq had completed a century off the 151st delivery he faced, Dimuth Karunaratne dropped him at slip off the bowling of Dilruwan. Hands began to go to Sri Lankan heads. Sarfraz and Shafiq had progressed so faultlessly on day four, that it seemed unlikely many more chances would come.
Then, suddenly: the breakthrough. Dilruwan got a ball to drift in towards the batsman, and Sarfraz - aiming a hard, flat sweep - managed only to get a thick top-edge to the ball. The man at long leg, Nuwan Pradeep, almost got tangled up in his own legs, but did well enough to take the catch cleanly. With only seven deliveries to be bowled before the second new ball was due, Sri Lanka had struck.
The remaining batsmen fell without notable resistance. Mohammad Amir was out to a Dilruwan slider off the ninth ball. Yasir Shah was stumped off Herath, attempting a giant heave. Lakmal shaped a ball away from Shafiq - who had not quite looked himself after getting to triple figures - and Kusal Mendis took another excellent tumbling catch at slip.
The final batting act of the series belonged to Wahab Riaz. Attempting to wallop Herath out of the ground, he wound up only sending a catch high in the air, to Chandimal at cover. On Sri Lanka's balcony, cricket manager Asanka Gurusinha broke into an uncharacteristically wide grin, and wrapped interim coach Nic Pothas up in a bear hug.
For Sarfraz, it was a return to earth, after his captaincy had begun so successfully with the victory at the Champions Trophy. For Chandimal, a victory in the first full series he has captained - the Zimbabwe match was a one-off, and he had not played the first match against India - has helped put some belief in his team, a quality that had previously been lacking. A series that was enlivened by a litany of twists has thrown up a startling result.
Andrew Fidel Fernando is ESPNcricinfo's Sri Lanka correspondent. @andrewffernando