Mahela Jayawardene remained unbeaten on 49 in his farewell innings after spinner Rangana Herath's career best figures of nine for 127 gave Sri Lanka control of the second test against Pakistan on Saturday.
Jayawardene, playing his last test, added 98 for the unbroken third wicket with his long-standing partner Kumar Sangakkara (54 not out) as Sri Lanka ended the third day against Pakistan on 177 for two wickets.
Sri Lanka, leading the two-test series 1-0, took an overall lead of 165 runs with eight second innings in hand and two days of the test match remaining.
Sangakkara and Jayawardene negotiated the Pakistan bowling, without injured Junaid Khan, skillfully on a turning track to put their team in a strong position at the end of the day.
Left-handed Sangakkara, who hit four boundaries, reached his 51st test half century before the close.
He survived a close call on 19 when Pakistan unsuccessfully reviewed a not out leg before appeal off Wahab Riaz with replays showing the ball hitting leg stump.
Jayawardene, with whom Sangakkara has associated in 46 half-century partnerships, hit seven fours during his 123-ball knock.
The 37-year-old was cheered by the sizeable crowd for every run he scored after walking out for his last test knock to a standing ovation and a guard of honour by the Pakistan players.
Left-arm spinner Abdur Rehman dismissed the Sri Lankan opener Upul Tharanga (45) and Kaushal Silva (17) in the afternoon session.
Tharanga hit four boundaries in his 63-ball innings before he dragged the ball on to his stumps while attempting a pull, ending an opening stand of 54 with Silva.
Silva fell to a catch at slip by Younus Khan.
Earlier, Herath's heroics restricted Pakistan's first innings lead to 12 runs with wicketkeeper Sarfraz Ahmed scoring his maiden test century.
Pakistan were all out for 332 at the stroke of lunch, replying to Sri Lanka's first innings total of 320.
The visitors' last four wickets added 88 runs to their overnight score of 244 for six, with Sarfraz (103) moving from 66 to his hundred with a superb pulled six off Chanaka Welegedara to become the first Pakistani wicket-keeper in five years to get to three figures.
Sarfraz held the Pakistan tail together during his 127-ball innings before Herath finally had him edging a catch to wicket-keeper Niroshan Dickwella.
Sarfraz hit one six and seven fours and added 40 runs with Abdur Rehman (16) for the seventh wicket and 28 with Wahab Riaz (17) for the eighth.
Herath continued to run through the Pakistan tail picking up the wickets of Rehman, caught by Jayawardene at slip, Riaz and Saeed Ajmal (four).
Junaid, who did not take the field after being hit by a Dhammika Prasad bouncer while batting, remained unbeaten on 13.
Herath's morning spell on Saturday was four for 29 off 8.1 overs. He became only the second Sri Lankan bowler to take nine wickets in an innings after former off-spinner Muttiah Muralitharan.
Should bouncers be banned from cricket?