Former captain Shoaib Malik scored a defiant undefeated century to give Pakistan a commanding 366-run lead at stumps on the third day of the third Test on Wednesday.
Pakistan, resuming on 16 for one, slowly consolidated their initiative with a hard-working batting display on a slow-scoring day, finishing on 300 for five at the close.
The 27-year-old right-hander faced 186 balls and hit 12 boundaries.
Misbah-ul Haq also contributed with a watchful 65 from 149 balls, sharing a crucial 119-run stand for the fifth wicket that sapped Sri Lanka's bowlers during a long hot afternoon.
The tourists showed their determination to avoid the humiliation of a series whitewash as they chiselled out 70 runs in the morning and 82 in the afternoon before accelerating in the final session.
Earlier, Pakistan were soon in trouble when Fawad Alam (16), Younus Khan (19) and Mohammad Yousuf (23) were all removed in the morning session.
Left-arm paceman Thilan Thushara made the first breakthrough when he caught Alam off his own bowling with a short delivery to reduce Pakistan to 22-2.
Nuwan Kulasekara then trapped Younus lbw after replacing Thushara in the attack, although TV replays indicated the Pakistan skipper had edged the ball onto his pads.
Left-arm spinner Rangana Herath was finally rewarded for his hard work when he had Yousuf caught behind in the final half hour before the break.
Sri Lanka were unable to make further inroads during the afternoon as Misbah and Malik played carefully against some tight bowling, taking no risks as they slowly built on the Pakistan lead.
All-rounder Angelo Mathews finally broke through in the final session with a delivery to Misbah that bounced steeply and found the outside edge.
But the wicket, taken just before the second new ball, did not change Sri Lanka's fortunes as Malik and Akmal raised the tempo in the final hour, extending their sixth-wicket partnership to 114 runs.
Sri Lanka lead the series 2-0 after wins in Galle and Colombo.