Mohammad Hafeez and Azhar Ali combined to keep Pakistan afloat in the third and final Test against Sri Lanka in Pallekele on Wednesday.
The overnight pair batted through most of the morning session on the fourth day as Pakistan wiped out the 111-run deficit in the first innings to reach 119-2 in their second knock by lunch.
Hafeez and Azhar, who both hit centuries in the drawn second Test in Colombo, put on 94 runs for the second wicket after Taufeeq Umar had fallen early on Tuesday evening.
Hafeez made 52 when he was dismissed 10 minutes before lunch, edging a wild drive off fast bowler Dilhara Fernando to Tharanga Paranavitana in the slips.
Azhar was unbeaten on 48 and veteran Younis Khan was on two with Pakistan, who are seeking a series-levelling win, ahead by eight runs with eight wickets in hand.
Younis put Pakistan in front by tapping Angelo Mathews for a single to point.
The wicket of Hafeez came against the run of play after Sri Lanka's bowlers failed to contain the flow of runs on a pitch that appeared to ease out under bright sunshine.
Sri Lanka lead the series 1-0, having won the first Test in Galle by 209 runs.