Opener Abdullah Shafique hit a gritty century to keep Pakistan in the hunt to chase down a victory target of 342 in the opening Test against Sri Lanka on Tuesday.
Pakistan ended day four on 222 for three, still needing 120 runs to take the lead in the two-match series at Galle, where the highest successful fourth-innings chase is 268 by Sri Lanka against New Zealand in 2019.
Shafique, batting on 112, and skipper Babar Azam, who made 55, put together 101 runs for the third wicket but spinner Prabath Jayasuriya broke through just a few overs before the close of play.
Jayasuriya bowled talisman Azam with his left-arm spin around the batsman's legs with a delivery that spun sharply from outside leg to rattle the stumps of the right-hander, who looked visibly shocked.
Wicketkeeper-batsman Mohammad Rizwan was batting on seven at stumps alongside Shafique, who had so far faced 289 balls and hit five boundaries and one six.
Pakistan began strongly with an 87-run partnership between Shafique and fellow opener Imam-ul-Haq, who made 35, but an alert stumping from wicketkeeper Niroshan Dickwella broke the stand.
The left-handed Imam missed a delivery from off-spinner Ramesh Mendis and Dickwella clipped off the bails, with the decision going up to the third umpire. After different TV angles it was established that Imam's foot was just millimetres off the ground when the bails were dislodged.
Azhar Ali was the next to go when he edged a ball from Jayasuriya to first slip. He made six off 32 deliveries.
Azam, who hit a defiant 119 in Pakistan's first-innings total of 218, then joined Shafique as the two rebuilt the innings on a turning pitch. Azam reached his fifty and two balls later Shafique got his second Test hundred with a single off Maheesh Theekshana, raising his bat to a standing ovation from the dressing room.
Azam, who crossed 10,000 international runs on day two and averages over 45, went past 3,000 Test runs during another stubborn knock. Jayasuriya, who claimed a five-wicket haul in the previous innings, kept up the pressure with his turners and sliders.
Sri Lanka took the second new ball in the 81st over but the spinners kept up the attack in the final few tense overs of the day.
In the morning, Sri Lanka resumed the day on 329-9 in their second innings. Dinesh Chandimal was stranded on 94 when they were all out for 337.