Both added centuries of their own as Sri Lanka extend prospects of a draw.
Dilshan and Sangakkara tons pile misery on Pakistan
Dilshan hit 121 before his removal in the 70th over, while Sangakkara reached stumps unbeaten on 144 as the hosts closed on 278 for five, still 273 runs behind Pakistan's mammoth first-innings total of 551 for six declared.
Pakistan's hopes of victory appeared to recede as Dilshan and Sangakkara took their second-wicket partnership to 225 runs - a record against this opposition - before Dilshan's dismissal triggered a collapse. Mahela Jayawardene and Thilan Samaraweera both fell without scoring, and Suraj Randiv fared little better, adding just five before he departed to the last delivery of the day.
On a rain-affected day, Dilshan and Sangakkara picked up where they left off as they continued to pile on the runs against a largely helpless Pakistan attack.
Sangakkara racked up his 30th career Test century, taking him past Don Bradman on the all-time list, in 180 balls.
Dilshan's century was achieved in two fewer deliveries as he became the eighth Sri Lankan to pass 5,000 Test runs.
Junaid Khan finally made the breakthrough after tea, removing Dilshan lbw with a delivery from around the stumps. Junaid repeated the trick to remove Jayawardene moments later.
Sri Lanka lead the three-match series 1-0 after winning the opening Test in Galle by 209 runs.
Follow us @SprtNationalUAE