Saud Shakeel's career-best 208 not out fetched Pakistan a significant first-innings lead of 149 in the opening Test against Sri Lanka at Galle on Tuesday.
Replying to Sri Lanka's first innings total of 312, Pakistan had slumped to 101-5 on Monday before Shakeel combined in a 177-run stand with Agha Salman, who made 83, to revive the visitors.
Shakeel remained unbeaten after his 361-ball knock that included 19 fours as Pakistan were all out for 461.
Sri Lanka finished day three on 14 for no loss and 135 behind after openers Dimuth Karunaratne and Nishan Maudushka saw off the last 3.4 overs in fading light.
Earlier, after Pakistan had resumed on 221-5, Salman threw away his wicket as he came charging down the track against Ramesh Mendis (5-136) only to miss the ball and be stumped.
By lunch, Pakistan had overtaken Sri Lanka and the lead continued to swell as Shakeel forged 50-plus partnerships with Noman Ali (25) and Naseem Shah, who made only nine but survived 78 balls to frustrate the hosts.
Left-arm spinner Prabath Jayasuriya finished with figures of 3-145.