Pakistan lost two wickets but opener Abdullah Shafique stood strong on 77 as the tourists chased 342 for victory on day four of the opening Test against Sri Lanka on Tuesday.
The visitors reached 147-2 at tea, still needing 195 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.
An 87-run partnership between Shafique, who raised his fifth Test fifty, and fellow opener Imam-ul-Haq was broken by an alert stumping from wicketkeeper Niroshan Dickwella.
The left-handed Imam missed a delivery from 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 left-arm spinner Prabath 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, denying Sri Lanka any more wickets in the second session.