Ramesh Mendis led an inspired Sri Lanka spin attack to leave Pakistan in trouble at 191-7 in reply to the hosts' 378 on day two of the second Test on Monday.
The tourists, who lead the two-match series 1-0, ended the day still trailing Sri Lanka by 187 runs in their first innings at Galle.
Agha Salman resisted the bowling attack with his maiden Test fifty but fell to Prabath Jayasuriya's left-arm spin for 62 in the final moments of play before stumps was called.
Jayasuriya got Salman caught at slip with a drifter coming into the right-handed batsman.
Salman, who made his debut in the previous match, put on 46 runs with Yasir Shah, batting on 13, to lift Pakistan from 145-6.
Ramesh rattled Pakistan's middle-order with his off-spin bowling on a pitch expected to turn more from day three onwards.
Pakistan suffered from a lack of partnerships after losing first-match hero Abdullah Shafique for a duck and skipper Babar Azam for 16 on either side of the lunch break.
Jayasuriya, who took 21 wickets in his first two Tests, bowled Azam on a turning delivery that got the edge of the dangerman's bat to crash onto the stumps.
Imam-ul-Haq attempted to rebuild the innings with Mohammad Rizwan but Dhananjaya de Silva broke through with his off-spin to send back Imam on 32.
De Silva is standing in as captain in place of Dimuth Karunaratne, who did not take the field in the Pakistan innings because of back pain.
Rizwan hit a few boundaries to counterattack but Ramesh trapped him lbw for 24 and a review did not help the wicketkeeper-batsman, with replays showing the ball would have hit leg stump.
Pakistan had lost opener Shafique, who hit a match-winning 260 in the first Test, when he inside-edged a delivery from Asitha Fernando onto his stumps.
Wickets kept tumbling but all-rounder Salman, who went wicketless in his six overs in Sri Lanka's innings, played the spinners on the front foot until his departure.
Sri Lanka had resumed the day on 315-6 in former captain Angelo Mathews' landmark 100th Test, with overnight batsman Niroshan Dickwella making 51 and a useful cameo of 35 by Ramesh at number nine.
Fast bowler Naseem Shah and leg-spinner Yasir claimed three wickets each to end Sri Lanka's innings in the first session.
Sri Lanka v Pakistan second Test scoreboard
Scoreboard after stumps on day two of the second Test between Sri Lanka and Pakistan in Galle on Monday:
Sri Lanka 1st innings (overnight 315-6; N. Dickwella 42, D. Wellalage 6)
O. Fernando c Rizwan b Nawaz 50
D. Karunaratne c Naseem b Yasir 40
K. Mendis run out (Salman) 3
A. Mathews c Rizwan b Nauman 42
D. Chandimal c Fawad b Nawaz 80
D. de Silva b Naseem 33
N. Dickwella c Rizwan b Naseem 51
D. Wellalage c Azam b Naseem 11
R. Mendis b Yasir 35
P. Jayasuriya lbw b Yasir 8
A. Fernando not out 4
Extras (b4, lb5, nb12) 21
Total (all out, 103 overs) 378
Fall of wickets: 1-92 (Oshada), 2-96 (K. Mendis), 3-120 (Karunaratne), 4-195 (Mathews), 5-258 (Chandimal), 6-290 (de Silva), 7-327 (Wellalage), 8-333 (Dickwella), 9-353 (Jayasuriya), 10-378 (R. Mendis)
Bowling: Hasan 17-3-59-0 (nb1), Naseem 18-3-58-3 (nb7), Nauman 21-2-64-1 (nb2), Agha 6-0-25-0 (nb1), Nawaz 19-3-80-2, Yasir 22-2-83-3 (nb1)
Pakistan 1st innings
A. Shafique b A. Fernando 0
Imam-ul-Haq b de Silva 32
B. Azam b Jayasuriya 16
M. Rizwan lbw b R. Mendis 24
F. Alam lbw b R. Mendis 24
A. Salman c de Silva b Jayasuriya 62
M. Nawaz c Dickwella b R. Mendis 12
Y. Shah not out 13
Extras (b8) 8
Total (7 wickets, 69.4 overs) 191
Yet to bat: H. Ali, N. Ali, N. Shah
Fall of wickets: 1-0 (Shafique), 2-35 (Azam), 3-65 (Imam-ul-Haq), 4-88 (Rizwan), 5-119 (Fawad), 6-145 (Nawaz), 7-191 (Salman)
Bowling: A. Fernando 14-1-49-1, Jayasuriya 27.4-7-59-2, R. Mendis 18-5-42-3, De Silva 4-0-15-1, Wellalage 6-1-18-0