Dimuth Karunaratne's second Test century lifted Sri Lanka to 272 for eight against Pakistan after Yasir Shah exposed their frailties against leg-spin on the opening day of the series-deciding third and final Test in Pallekele.
At 106 for one in the second session, Sri Lanka looked poised for a big first-innings total before Shah, who took 17 wickets in the first two matches, tormented them again with his flight and variation to claim four for 77.
Tharindu Kaushal was batting on 17 with Suranga Lakmal (one) after Shah had wrecked the top order and part-time leg-spinner Azhar Ali claimed two late wickets in two balls to peg back the hosts.
Opinion: Don't go overboard with all-rounders
Karunaratne fell for 130 off 230 balls, hitting 14 fours in a patient knock which rescued Sri Lanka.
The hosts lost Kaushal Silva (nine) in the morning session when the batsman edged paceman Rahat Ali, one of the four new faces in the Pakistan team, to be caught-behind.
Karunaratne added 91 with Upul Tharanga (46) to steady the innings but Shah wreaked havoc after lunch as Sri Lanka lost three wickets for the addition of just 31 runs.
Tharanga was outfoxed by a Shah googly that took the outside edge, deflected off wicketkeeper Ahmed's pads and ballooned up for Younus Khan to take a diving catch at slip.
Lahiru Thirimanne needed 17 balls to get off the mark before he decided to come down the track and hit a Shah delivery straight to mid-off.
Skipper Angelo Mathews, the only member of the Sri Lankan side to have played more than 25 Tests, was also guilty of poor shot selection, hitting Shah straight to mid-on.
Azhar struck back-to-back blows by dismissing Karunaratne and Dhammika Prasad off successful deliveries as Sri Lanka lost four wickets in the final session.
Sri Lanka 272-8 (Karunaratne 130, Shah 4-77)