Sri Lanka started the day-4, 199 runs behind but Kumara Sangakkara and Angelo Mathews wiped off the deficit with a 181-run partnership for the fourth wicket.
Sangakkara, who made 221 – his 11th double of his career, went past West Indian Brian Lara and become second behind Don Bradman’s 12 in the list of batsmen with most double-centuries.
He is fast creeping up on the three legends ahead of him on the run-scoring charts – Jacques Kallis (South Africa), Ricky Ponting (Australia) and Sachin Tendulkar (India)- and it would be no surprise if he goes on to surpass all of them.
Sri Lankan skipper Matthews (91) got dismissed just before tea for the fifth time in the nineties, the last three of which have all been against Pakistan, and all 91s.
The hosts declared the inning after the fall of Dhammika Prasad (31) at 533 and had a healthy lead of 84 runs before leaving Pakistan’s tired batsmen 20 minutes to survive till stumps.
Pakistan was poor in field as they dropped Sangakkara at first ball in the morning off Junaid Khan, and then on 168 off Saeed Ajmal.
Saeed Ajmal figures are 59.1-8-166-5 and it was his most expensive five.
Abdur Rehman was used much less than. He bowled 39 overs and conceded 123 runs taking 1-wicket.
Sri Lanka with a lead of 78 are right ahead having the chance to put the visiting batsmen under serious pressure on the final day.