Sri Lanka's batsmen showed remarkable poise on a wearing pitch to thwart Pakistan's spinners and regain control of the first Test in Galle on Monday.
Dinesh Chandimal capitalised on his red-hot form, scoring his second successive half-century of the match to take Sri Lanka's lead past 300 on day three.
The hosts were 329-9 when bad light stopped play in Galle. Chandimal, batting on 86, and Prabath Jayasuriya, on four, were together at close of play with Sri Lanka leading by 333 in their second innings.
It marked a dramatic turn of events a day after Pakistan captain Babar Azam scored a sparkling century to single-handedly take the visitors close to Sri Lanka's first innings score of 222.
On Monday, Chandimal, who hit his maiden double century in his team's series-levelling Test win over Australia last week, stood firm in another lower-order show of defiance after the hosts slipped to 235-7.
Left-arm spinner Mohammad Nawaz claimed his maiden five-wicket haul and combined with fellow spinner Yasir Shah, who took three, to rattle the opposition middle-order in the second session.
Chandimal reached his fifty and put on 41 runs with Maheesh Theekshana for the ninth wicket in a repeat performance from the hosts, who had hit back from 133-8 to post 222 in their first innings.
Pakistan had an opportunity to dismiss Chandimal when he was on 68 but Hasan Ali put down a return catch.
Earlier Kusal Mendis made 76 and opener Oshada Fernando scored 64 and put on a key third-wicket stand of 91 to fight back after an early wicket in the morning session.
Oshada reached his sixth Test fifty in the first session but fell to Yasir on the second ball after lunch. Kusal reached his fifty and took on the opposition attack with a few boundaries before Yasir bowled him with a delivery that pitched outside leg and turned to hit the top of off stump.