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.
"He is one of the best players, so he provided good support while batting and guided me all along on how to play," Shafique, who called his ton a "special one", said of captain Azam.
"So was a not a good thing when he got out but now the responsibility lies on me."
Left-arm spinner Jayasuriya bowled talisman Azam 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.
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.
Various TV angles 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, who claimed a five-wicket haul in the previous innings, to first slip. He made six off 32 deliveries.
- 'Still in the game' -
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.
"All of a sudden the wicket went flat... still we kept them under three runs and we did a marvellous job on that track," Sri Lanka's spin coach Piyal Wijetunga told reporters.
"We are still in the game. If we grab two wickets in the morning session we have a great chance of winning this game."
Azam, who crossed 10,000 international runs on day two and averages over 45, went past 3,000 Test runs during another stubborn knock in which he hit Jayasuriya for a few boundaries and one six.
Shafique also hit his only six against Jayasuriya and said things went to plan.
"We have just one plan in mind and that is to go after Jayasuriya," said Shafique.
"He has done well in the first innings and if we figure him out well here then we have a pretty good chance of batting well against them."
Sri Lanka took the second new ball in the 81st over but the spinners kept up the attack in the tense final 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.