Pakistan lost three wickets in a tricky 131-run chase on day four of the rain-hit opening Test on Wednesday to give Sri Lanka a glimmer of hope in the contest.
The tourists reached 48-3 at stumps in Galle, needing another 83 on the fifth and final day to take the lead in the two-match series.
Pakistan spinners Noman Ali and Abrar Ahmed took three wickets each to help bowl out Sri Lanka for 279 in the final session despite a stubborn 82 by first-innings centurion Dhananjaya de Silva.
Pakistan opener Imam-ul-Haq, on 25, and skipper Babar Azam, on six, were batting at close of play.
Left-arm spinner Prabath Jayasuriya struck twice with the wickets of Abdullah Shafique, caught behind for eight, and Shan Masood for seven.
Noman was sent in as nightwatchman but he was run out on nought.
"Ideally, we should have had another 100 runs more on the board but since the first innings lead (by Pakistan) we were always playing catch up cricket," Sri Lanka assistant coach Naveed Nawaz told reporters.
"If we can get another two-three wickets without conceding too many runs tomorrow it could turn out to be a good contest."
Left-armer Noman, Abrar and Agha Salman, who took two wickets, struck regular blows in Sri Lanka's second innings.
Pace spearhead Shaheen Shah Afridi snared another two to help clean up the tail.
De Silva, who scored 122 in Sri Lanka's first-innings total of 312, built key partnerships including a 76-run seventh-wicket stand with Ramesh Mendis, who made 42.
Shaheen, a left-arm quick, finally got de Silva caught behind with a rising delivery after Pakistan took the second new ball.
Shaheen got his second before Abrar ended the innings.
Salman sent back Dinesh Chandimal for 28 to break a 60-run stand with de Silva and then Samarawickrama for 11 to put Sri Lanka in trouble, but de Silva stood firm.
Abrar struck first earlier with his leg spin to send back skipper Dimuth Karunaratne for 20 to check Sri Lanka's brisk start.
Batsman Saud Shakeel has remained the star for Pakistan so far with his unbeaten first-innings 208 -- his maiden Test double century -- in his team's 461 all out on day three.
Shakeel's marathon knock handed Pakistan a handy lead of 149 as rain interrupted play on the first three days.
Rain stayed away on day four, which started late due to a damp patch on the field.
str/fk/dva