Pakistan made a bright start to their second innings, but lost in-form opener Abdullah Shafique, before tea, having been set 508 for victory. Although a draw is realistically the best they can hope for, Pakistan were nevertheless intent on playing their shots, as Sri Lanka maintained a tight infield.
Imam-ul-Haq had got to 41 off 64 by the end of the afternoon session, having lived dangerously in that time. Shafique had holed out trying to hit over the top too. The visitors were 71 for 1 at the break.
All this was after Dhananjaya de Silva had completed his ninth Test century, and Sri Lanka had added 63 quick runs at the start of the session - Ramesh Mendis cracking 45 not out off 54 balls. All up, that stand between de Silva and Ramesh was worth 82, and came off 101 deliveries.
The more vital partnership that de Silva was involved in this innings, however, had been with Dimuth Karunaratne - the pair having come together at 117 for 5 on day three. In Wednesday's morning session, they had each had a little luck early on. De Silva had mis-hit a cut shot against Hasan Ali in the second over, and the inside edge passed perilously close to the stumps. Karunaratne then played back to Nauman Ali's first over of the day, and would have been lbw had the umpire given him out on the field. In the end, Pakistan reviewed, and Karunaratne's was saved by an umpire's call on line.
Eventually, though, the batters settled and the runs began to flow. De Silva used the sweep to excellent effect, once slogging Yasir Shah over midwicket for four, while Karunaratne used the reverse sweep to access empty space behind point. Largely, though, the batters preferred to use their feet to find the single options. Karunaratne brought up his half century off the 97th ball he faced; de Silva off his 102nd, two overs later.
Karunaratne was out to an excellent reflex catch at short leg by Shafique, off Nauman's bowling. But by that stage, the pair had put on 126 together and delivered Sri Lanka to an incredibly strong position.
De Silva went to lunch on 84, and needed only 16 balls to complete his century in the company of Ramesh, as he found square boundaries on either side of the pitch with relative ease against the spinners.
Ramesh then attacked to speed Sri Lanka towards their declaration, which only came when de Silva was run out for 109 at the non-striker's end. Ramesh seemed to have called his partner through for a run, but sent him back when it was clear that Yasir Shah was swooping on the ball from midwicket. Yasir's direct caught de Silva metres short.
Shafique had batted out 50 balls for his 16, but was perhaps looking to spread the field by striking a couple of boundaries, when he ran down the track and tried to lift Prabath Jayasuriya over mid off. He hadn't got to the pitch of the ball, though and ended up sending it high in the air between mid off and cover instead. Dunith Wellalage ran back from mid-on to get under the swirling ball.
Imam was almost caught at short leg on 35 (the ball bounced just short of the fielder), and survived a couple of big lbw appeals. Babar Azam went to tea on 14, having struck a short Jayasuriya ball for six in the over before the break.