Pakistan's innings was interrupted when bad weather stopped play for the second time in the day forcing the players to take tea early and no play was possible in the final session.
When play was called off for the day, Pakistan, trailing 1-0 in the three-Test series, had reached 488 for four wickets with captain Misbah-ul-Haq (29) and Asad Shafiq (one) at the crease.
Heavy passing showers interrupted play twice shortly before the lunch and tea breaks and only 44.2 overs were bowled all day, with Pakistan adding 154 runs and losing three wickets.
Sri Lanka managed to snap up two wickets during the curtailed afternoon session when they dismissed Younus Khan (32) and Azhar Ali (157) - both wickets falling to the spinners.
Younus' innings was ended by left-arm spinner Rangana Herath who trapped him lbw on the sweep to a straight ball pitching on middle and off.
Azhar equalled his career best Test score of 157 but his marathon knock came to an end shortly before the rain came down when he tried to reverse sweep a delivery from Suraj Randiv.
The resulting top edge was held at backward point by Nuwan Kulasekera ending a 7-1/2 hour innings that included only nine boundaries and spanned 295 balls.
It took Azhar an hour to move from 94 to 100 and his third Test ton in the morning session.
Earlier, Pakistan lost opener Hafeez on 196, as they looked to build on their first day total of 334 for one before rain forced the players off for an early lunch 10 minutes before the scheduled break.
Right-handed Hafeez, unbeaten on 172 overnight, attempted a sweep shot against Herath but missed the line of the ball and had his leg stump uprooted.
Hafeez, who hit 20 fours and a six during his 331-ball knock, departed after batting for more than seven hours.
His exit ended a second-wicket stand of 287 with Azhar, who remained unbeaten on 121 at the break.
Azhar completed his third Test hundred with a ferocious cut off Nuwan Pradeep to the point boundary.