Hafeez, a late inclusion in the squad after a double hundred in a domestic match, was unbeaten on 113 while fellow opener Imam-ul-Haq was 75 not out after Pakistan won the toss and made a decision to bat on a flat Dubai Stadium pitch.
Shafiq (80, 165 balls, 9 fours, 1 six) missed out on what could have been his 10th Test century at number six in the batting order.
Australian captain Tim Paine faced criticism for not taking the new ball until the 120th over, allowing Shafiq and Sohail to settle at the crease.
But Sohail and Shafiq soon began playing with freedom and took the Pakistan score to 394/4 at lunch.
Australia´s openers survived a torrid 13 over spell to finish on 30 without loss after Haris Sohail´s maiden century guided Pakistan to 482 on the second day of the first Test in Dubai on Monday.
Mahrez miss leaves City, Liverpool and Chelsea all level at top
As for what it means for the standings, there is now a three-way tie for first with teams having records of 6-2-0. We were close, more than ever to winning here but it is better than last season, we didn't lose.
Debutant Marnus Labuschagne earlier demonstrated his value as a triple-threat, inspiring the visitors with the ball and in the field. Shafiq got to his 50 - 21st in Test cricket - first with a trademark square cut for a four while Sohail reached it in the very next over with an exquisite cover-drive off Lyon.
Fast bowler Peter Siddle was the pick of the bowlers with 3-58 while Lyon finished with 2-114 from 52 overs.
It was for the eighth time in Test cricket both the captains also kept wickets and the last time this happened was in September 2014 - Denesh Ramdin and Mushfiqur Rahim at Gros Islet. Australia handed Test caps to Aaron Finch, Travis Head and Marnus Labuschagne while Pakistan included off-spinner Bilal Asif for his first Test at the age of 33. Pakistani opener and veteran Mohammad Hafeez is returning to the national team after almost two years.
The second and final Test will be played in Abu Dhabi from October 16.
Receiving little assistance from a road-like deck nearly entirely devoid of grass, Mitchell Starc and recalled workhorse Peter Siddle combined for just eight overs before offspinner Nathan Lyon was brought into the attack. ERROR: Macro /ads/dfp-ad-article-new is missing!