Pakistan 215 (Sarfraz 78*, Azhar 52) and 380 for 3 (Younis 171*, Masood 125, Misbah 59*) beat Sri Lanka 278 (Karunaratne 130, Yasir 5-78) and 313 (Mathews 122, Chandimal 67, Imran 5-58) by seven wickets

Scorecard and ball-by-ball details

play 6:20 Bazid: Pakistan might struggle to replace Younis and Misbah Sri Lanka correspondent Andrew Fernando is joined by former players Bazid Khan and Russel Arnold to discuss Younis Khan's heroic effort and Misbah-ul-Haq's importance as Pakistan registered a famous win against Sri Lanka

Younis Khan's epic, unbeaten 171 led Pakistan to their highest successful chase, the second highest in Asia for any side, and the sixth highest in all Test cricket. It also gave them their first series win in Sri Lanka since 2006, and catapulted them to third in the ICC Test rankings.

The feat required the highest fourth-innings partnership for Pakistan, 242 between Younis and Shan Masood, who fell on the fifth morning for 125. Misbah-ul-Haq arrived with 122 needed, saw off Sri Lanka's quicks till lunch, and opened up after that to reel off an unbeaten 59, finishing the match with a six.

Sri Lanka's fast bowlers put in a spirited effort, especially with the second new ball, but could not break down Younis and Misbah.

Pakistan needed 147 more at the start of the day, and Masood and Younis' record partnership grew by 25 before the former fell to his nerves. Masood had been tied down by Sri Lanka's accuracy, and was itching to break free. No release was provided by Angelo Mathews and the specialist seamers. When the offspinner Tharindu Kaushal was introduced in the 11th over of the morning, Masood, eyeing some runs, jumped out, but was beaten by the turn to be stumped.

Sri Lanka's specialist spinner had begun promisingly after a wayward return of 0 for 92 in 20 overs on day four, but again, he failed to sustain the pressure. He did shift his line wider outside off and spun it in sharply with men waiting in the leg trap, but was too inconsistent with his lengths. Misbah and Younis used the sweep frequently, and put away the regular full tosses with ease.

It was a different story against the quicks. The first boundary of the day came only in the tenth over, when Younis forced an edge through the vacant slip region off Nuwan Pradeep.

There was little in the pitch by way of variable bounce to suggest it was a day-five subcontinent wicket. Despite their discipline at the start, Sri Lanka were dependent on the new ball. Pakistan needed 101 more when it was taken, and they had the personnel in the middle to get them through.

Misbah was happy to deny himself against the new ball, going 22 balls without a run. Batting on a big hundred, Younis was eager to move across and play as much as he could. There was an unsuccessful review for leg-before against Younis, on 128, by Dhammika Prasad, replays returning umpire's call for points of impact on pad and stumps.

As Mathews tried Kaushal again at the stroke of lunch, Misbah stepped out to lift him over mid-on. Sri Lanka's challenge fell apart after lunch, Misbah and Younis raining boundaries on the hapless Kaushal, who had played ahead of veteran Rangana Herath, and was to end with figures of 1 for 153 in 31 overs.

The winning runs came again from Misbah's bat, as they had come during their Sharjah chase of 302 against Sri Lanka in 2014. Younis ended with the fifth-highest score in a chase.