Dimuth Karunaratne fell agonisingly short of a maiden Test double-century and Pakistan lost Mohammad Amir to injury on day two in Dubai as Sri Lanka gave themselves an excellent chance to seal a series victory.
Karunaratne anchored the Sri Lanka innings with a magnificent Test-best 196 with support from Dinesh Chandimal (62), Niroshan Dickwella (52) and Dilruwan Perera (58) to get the tourists - leading the two-match series 1-0 - up to 482 all out.
Amir left the field in the afternoon session due to a shin injury that will prevent the paceman from bowling in the second innings and keep him out of the one-day international series.
Yasir Shah (6-184) claimed a five-wicket haul for the fifth consecutive Test as Pakistan toiled without Amir, who is available to bat, before Sami Aslam and Shan Masood saw them through to 51-0 at stumps
Captain Chandimal brought up his half-century after Sri Lanka resumed on 254-3, but missed out on a second century of the series when he was given out leg before and decided against reviewing despite replays showing Yasir's delivery was missing the stumps.
Karunaratne continued to make Pakistan suffer with Amir departing for a scan after bowling only three overs, working the ball into the leg side with great skill and countering the threat of Yasir as the aggressive Dickwella played his shots at the other end.
Dickwella attacked Yasir and struck five fours to add some impetus to the innings, Sri Lanka moving on to 355-4 at tea with the composed Karunaratne easing past 150 and reaching the 3000-run mark at Test level.
The in-form Dickwella helped himself to a seventh Test half-century before Mohammad Abbas ended an 88-run stand by snaring the wicketkeeper-batsman caught behind.
Karunaratne missed out on a maiden Test double-century when he played on to a delivery from Wahab Riaz, who earlier took six attempts to bowl the fifth ball of an over before finally getting his run-up right.
Dilruwan struck seven boundaries and Rangana Herath added an unbeaten 27 as Sri Lanka piled on the runs to ensure Yasir was in no mood to celebrate yet another five-wicket haul.
Masood had a stroke of luck when he was given not out and Chandimal chose not to review after Dilruwan struck the opener in front, replays showing he should have been given, and Aslam ought to have been run out following a mix-up but Pakistan got through to stumps without losing a wicket.