Hafeez fell for 196 and Azhar equalled his highest score as the tourists moved from their overnight position of 334-1 to 488-4 on a rain-hit second day at the Sinhalese Sports Club in Colombo.
Heavy showers on either side of lunch and just before tea allowed just 44 overs to be bowled in the day, in which Pakistan scored 154 runs.
Bollywood celebs show you colours for Navratri 2017
Photos: Kareena Kapoor Khan, Kangana Ranaut at the Mumbai airport
Birthday special: Chris Gayle and his multiple records in cricket
In Pictures: 17 dreaded on-screen villains of Bollywood
'Ramayan' director's great granddaughter Sakshi's hottest photos