Sri Lanka 320 and 177 for 2 (Sangakkara 54*, Jayawardene 49*) lead Pakistan 332 (Sarfraz 103, Herath 9-127) by 165 runs
Scorecard and ball-by-ball details

Twice, in this match, Pakistan's perseverance had meant Sri Lanka were not allowed to run away too far ahead. The home side, sitting on a 1-0 lead, won the toss on a batting-friendly pitch, but were restricted to a slightly below-par 320 by Pakistan's seamers. Rangana Herath then quaked the Pakistan batting line-up with a career-best nine-wicket haul - the best by a left-arm bowler, but the visitors, led by a counterattacking century from wicketkeeper Sarfraz Ahmed, still managed to post a slender first-innings lead.

Sri Lanka's third advance, though, was the one threatening to take the match, and the series, way beyond Pakistan's reach. It came from familiar quarters: the Kumar Sangakkara-Mahela Jayawardene combine. The two, batting together for the last time in Tests, blunted the Pakistan spinners during a period where they were extracting help from the pitch and added an unbeaten 98 runs to drive Sri Lanka into a strong position. During the course of their stand, the two also went past Desmond Haynes and Gordon Greenidge to become the second-most prolific duo in Tests.

In the absence of Junaid Khan, who sat out the last two sessions after being hit on the helmet grille while batting, Pakistan's three frontline bowlers toiled for 61 out of 63 overs and were only able to dislodge the Sri Lanka openers.

As has been the trend in this Test match, the SSC pitch offered much more to the bowlers in the last session. Few stayed low, some turned and bounced, and a couple beat the inside edge of Sangakkara's bat as he went for the drive, a rare sight in itself. But if one had to pick two batsmen for such conditions, Jayawardene and Sangakkara would be top choice for most. They tired out the bowlers with their immaculate defence but played the most exquisite drives the moment the bowlers erred. Sangakkara reached yet another half-century with a paddle to fine-leg boundary in the last over of the day while Jayawardene, unbeaten on 49, was on course to make it a memorable farewell.

The calmness with which Sangakkara and Jayawardene played was in complete contrast with the frantic morning session during which the two teams traded blows. The pitch was firmer and there was not much for the bowlers but that did not have much effect on the approach of Herath, who went on to pick up all four Pakistan wickets to fall.

That Pakistan managed a slender 12-run lead was down to Sarfraz Ahmed, the Pakistan wicketkeeper, who has been prolific in each innings in this series - he has gone past 50 every time. Sarfraz reserved his best for the SSC, after Pakistan had slid to 140 for 5 on the second day and were in danger of losing the advantage of restricting Sri Lanka to 320.

He became the first Pakistan wicketkeeper to hit a century - his first in Tests - since Kamran Akmal's unbeaten 158 against Sri Lanka in Karachi in February 2009.

Starting the day 76 short of Sri Lanka's total, Sarfraz was the key for Pakistan if they were to get close. And the batsman's busy approach meant he didn't let the bowlers settle on one line. The sweep and the cut were his most profitable allies as he continued to collect runs at a brisk pace. As Sri Lanka waited for the new ball, Sarfraz calmly kept the scoreboard moving with neat manoeuvres, a powerful sweep from outside off to Angelo Mathews standing out among his early runs on the day.

Before reaching his century, Sarfraz lost Abdur Rehman after a 40-run stand - the batsman edging Herath to Jayawardene at first slip - and Wahab Riaz, who scored 17. On 90, he twice swept seamer Chanaka Welegedara off consecutive balls, hitting a four and a six to reach his maiden hundred off only 109 balls. The loud shriek of excitement as he celebrated the landmark reverberated around the ground. He received a standing ovation from the Pakistan dressing room that was relieved to see a possible setback had been single-handedly averted.

After adding three more runs though, Sarfraz was dismissed in typical Herath fashion: the flight drawing the batsman forward, then turning to take the outside edge. It was only the second dicey shot Sarfraz played off the spinner after staying in command throughout his innings. It was also Herath's eighth wicket. The bowler picked up another one with a slider to become the first bowler since Muttiah Muralitharan, in 2002, to bag a nine-wicket haul. He already has 18 dismissals this series, and will have his eye on Murali's record of 22 wickets in a two-match Test series.

Devashish Fuloria is a sub-editor at ESPNcricinfo