Mahela Jayawardene scored an unbeaten 49 in his last Test innings as Sri Lanka took charge of the second and final match against Pakistan in Colombo on Saturday.
The hosts, who trailed by 12 runs on the first innings, put on a strong batting performance to move to 177-2 in their second innings by stumps on the third day at the Sinhalese Sports Club.
Jayawardene and his close friend and long-time teammate Kumar Sangakkara batted together for the last time in a Test match to put on 98 for the unbroken third wicket.
Jayawardene, who was warmly applauded to the crease by Pakistani fielders and some 4,000 home fans, played fluently to strike seven boundaries.
Left-handed Sangakkara was unbeaten on 54, with Sri Lanka 165 runs ahead with eight wickets in hand on a wearing pitch expected to assist spinners on the last two days.
Sri Lanka, who won the first Test in Galle by seven wickets, are hoping to sweep the short series to give Jayawardene, their former captain, a winning farewell.
Upul Tharanga made 45 in an opening stand of 54 with Kaushal Silva before both batsmen were dismissed by left-arm spinner Abdur Rehman in the post-lunch session.
Pakistan seamer Junaid Khan did not take the field in the second innings as he was taken to hospital and kept under observation after complaining of giddiness.
Junaid, who took five wickets in the first innings, had been hit on the helmet by a rising ball from Dhammika Prasad in the morning session.
Earlier, Pakistan's wicketkeeper Sarfraz Ahmed smashed a maiden Test century and Sri Lanka's spinner Rangana Herath became the first left-arm bowler in history to take nine wickets in an innings.
Sarfraz hit a gutsy 103 as Pakistan carried their overnight score of 244-6 to 332 before they were all out at the stroke of lunch in reply to Sri Lanka's 320.