Kumar Sangakkara's 10th double century put him just two behind Australian great Don Bradman's 12 as Sri Lanka declared at 533 for nine wickets for an 82-run first innings lead before returning to strike a late blow as well.
Pakistan were four for one wicket in their second innings at stumps, having lost opener Khurram Manzoor for three to Rangana Herath.
Ahmed Shehzad was one not out and Saeed Ajmal yet to open his account with Pakistan still trailing by 78 runs with nine wickets in hand.
The day, however, belonged to Sangakkara who brought up his double century with a single off Ajmal, sparking off celebrations in the ground.
His batted for 11 hours and 38 minutes, hitting 24 fours in his marathon 425-ball knock.
Sangakkara endured some torrid moments, however, before reaching the double century when Ajmal followed up the dismissal of Angelo Mathews (91) before the tea break with a further three cheap wickets as Sri Lanka slumped to 475-7.
Ajmal, without a wicket in the previous 47 overs, picked up four for 13 in 6.3 overs, also dismissing Kithuruwan Vithanage, Niroshan Dickwella and Dilruwan Perera.
Sangakkara's marathon knock came to an end when he stepped out to Abdur Rehman and was stumped by wicket-keeper Sarfraz Ahmed.
Sri Lanka appeared set to bat through the afternoon session unscathed until Pakistan picked up the wicket of Mathews when the batsman pushed forward at an Ajmal delivery and was caught in the slip.
The dismissal ended his 181-run stand with Sangakkara.
Earlier Sangakkara, still on his overnight score of 102, cut the first ball he received from Junaid Khan straight to point where Abdur Rehman spilled an easy catch.
At the other end, Mahela Jayawardene, making his penultimate test appearance, got off the mark for the day with a streaky four off Junaid but was out the next ball when he was trapped lbw on 59.
Jayawardene's dismissal ended a 113-run partnership with Sangakkara for the third wicket but was the only success for the visitors in a morning session that was extended to make up for lost time due to rain on Friday.
Dhammika Prasad got a caught behind decision successfully overturned off the first ball he faced and went on to score a useful 31 off 35 balls taking Sri Lanka past the 500-run mark before providing Ajmal with his fifth wicket of the innings.