Melbourne: Pakistan were six for 310 at the close on the second day of the second Test against Australia at the Melbourne Cricket Ground on Tuesday.
Azhar Ali was unbeaten on 139 and Mohammad Amir was not out 28 when rain forced an early end to the day.
It was Azhar's 12th Test century and third against Australia.
After rain washed out much of day one, Azhar and Shafiq resumed on 4-142 on an overcast day at the MCG and built a 115-run partnership to steer Pakistan safely to the first break.
Azhar was unbeaten on 139, having notched his 12th century, with the in-form Shafiq out for 50. He falls with new ball when play resume after tea.
Australia's pacemen were unable to garner much from the pitch and were despatched all over the ground as the old ball came to the end of its life.
Having taken over 90 balls to strike his first boundary on day one, Azhar opened his shoulders and his sixth four was a glorious off-drive off paceman Jackson Bird to bring up the pair's 50-run partnership.
At 4-185, with the batsmen entrenched, Smith squandered a review after an appeal for caught behind against Shafiq was turned down, but the technology picked up no edge as Bird's delivery went through to wicketkeeper Matthew Wade.
A short break for rain left Azhar stranded on 96, and Smith introduced himself and Nic Maddinson to bowl some part-time spin in an attempt to dislodge the opener.
On 99, though, Azhar glanced two runs down the leg-side off Maddinson to bring up the milestone, giving a little hop of joy before embracing Shafiq in celebration.
Shafiq, named Man of the Match for his fighting century in the 39-run first test loss in Brisbane, smashed spinner Nathan Lyon for consecutive fours to bring up the hundred partnership off 195 balls.
Brief scores
Pakistan - 6 for 310 (Azhar Ali 139*, Shafiq 50, Bird 3-91)