Sarfraz Ahmed frustrated Sri Lanka's bid to win the second test inside four days by hitting his maiden test half century and steering Pakistan to 330-7 today, a lead of 107.
The wicketkeeper made an unbeaten 70 off 123 balls with seven fours after he was flown in as a replacement for the injured Adnan Akmal.
Ahmed was supported by No 8 Bilawal Bhatti, who made 32, before rain ended the fourth day 15 overs early.
Pakistan, trailing by 223, was just 22 runs ahead when Rangana Herath got through the defences of captain Misbah-ul-Haq for 97, putting Pakistan on 245-6.
"When Misbah got out I tried to take the responsibility because I have batted through these types of situations in first class cricket back home," Ahmed said.
Ahmed and Bhatti confidently batted in overcast conditions in the last session and added 67 runs to push the test into the last day.
"The first hour (Sunday) is very important for us, if we survive then definitely we will score too," Ahmed said. "They will also be under pressure ... If we score another 100 runs in two sessions, it will give us a good chance to come back into the match."
Bhatti was unlucky to get bowled when Shaminda Eranga's full pitched delivery rolled back onto his stumps, but Saeed Ajmal survived the last half hour to be unbeaten on 7.
Ahmed tackled the swing of seamers by standing at least a foot outside his crease and confidently used his feet while negotiating the spin of Herath. He completed his half century off 73 balls with six fours.
Misbah missed his second successive century but batted almost seven hours and faced 248 balls before Herath opened up the Pakistan tail just before tea.
"We needed that wicket because he's the one who batted really well with Younis," Herath said. "I think I bowled a good delivery, but apart from that I couldn't get much spin from this pitch."
Resuming at the overnight 132-3, Pakistan lost Younis Khan for 77 off a reckless shot when he edged Suranga Lakmal in the 11th over of the day.
Sri Lanka allowed Pakistan to add only 57 runs in the morning session under overcast conditions with Misbah scoring his first runs of the day after an hour and facing 37 balls.
Misbah, who was 53 overnight, slowly stretched the fourth wicket stand to 129 with Khan as Sri Lanka seamers Eranga and Nuwan Pradeep kept the pressure on.
Khan succumbed to the probing line and length by giving wicketkeeper Prasanna Jayawardene his fourth catch of the innings.
Misbah successfully overturned an lbw decision on 78, but Shaminda Eranga found the edge of Asad Shafiq for 23 immediately after the second new ball was taken after lunch.
Jayawardene, who also took four catches in the first innings, needs one more to equal Amal Silva's Sri Lanka test record of nine catches. Silva took nine catches twice during the series against India in 1985.
Misbah scored his first runs of the day when he flicked Lakmal to backward square leg for two runs before edging a boundary in the same over through the slips.
Indian umpire Sundaram Ravi ruled Misbah out lbw off Eranga when Pakistan still needed 28 runs to erase the first innings deficit, but TV replays suggested the ball would have missed the leg stump.
Eranga broke through in his first over with the second new ball when Shafiq edged to the second slip before Herath drew Misbah forward and got enough turn to beat the bat and hit the stump. Misbah, who also scored a century in the first test, hit eight fours and a six before he was undone by Herath's superb delivery.
Pradeep, who did the early damage on Friday, has taken 2-50 and Eranga got 2-70. Herath, who also bowled with the second new ball, has 2-124.
The first of the three-test series was drawn.
Who's the best test cricket captain?