Skipper Babar Azam made a defiant 119 before Pakistan were bowled out for 218 on day two of the first Test against Sri Lanka on Sunday.
Azam single-handedly took the tourists to just four runs short of Sri Lanka’s 222 as he put on a 70-run 10th wicket stand with Naseem Shah, who made five not out off 52 balls in Galle.
At stumps, the hosts were 36-1 in their second innings, an overall lead of 40.
Left-arm spinner Prabath Jayasuriya claimed his third successive haul of five wickets or more to rattle the opposition batting, which slumped to 85-7 before lunch and then 148-9 in the second session.
Azam reached his seventh Test century driving mystery spinner Maheesh Theekshana, who finally got the star batsman trapped lbw to end the Pakistan innings in the final session.
Azam got help from the lower-order batsmen including Yasir Shah (18), Hasan Ali (17) and Naseem, as Pakistan managed 133 runs for the final three wickets.
Azam shielded number 11 Naseem by facing most of the balls in a defiant show of batting.
He hit fast bowler Kasun Rajitha for three straight boundaries and later a six and four off Theekshana and Jayasuriya.
For Sri Lanka, it was a taste of their own medicine after they had fought back from 133-8 on Saturday when Pakistan left-arm quick Shaheen Shah Afridi took four wickets.
Pakistan resumed the day on 24 for two when play started 30 minutes late because of rain and Azhar Ali could only survive three balls before he was trapped lbw by Jayasuriya.
Debutant Salman Ali Agha’s stay lasted just 15 balls before he was out leg before to another sliding delivery from Jayasuriya having scored five.
Jayasuriya, 30, then struck on successive deliveries to remove Mohammad Nawaz and Shaheen Shah Afridi before Yasir survived the hat-trick ball.