Hafeez remained unbeaten on 137 with Pakistan reaching 227 for one in their first innings at stumps after Bangladesh were shot out for 332. Azhar Ali was also not out on 65.
Bangladesh resumed on 236 for four and went past 300 riding on a 62-run stand for the sixth wicket between captain Mushfiqur Rahim (32) and debutant Soumya Sarkar (33).
Sarkar and Rahim fell in consective overs as Bangladesh, who defeated Pakistan in all four limited overs matches preceding the two-test series, collapsed from 305 for 5 to 332 all out.
Paceman Wahab Riaz and leg-spinner Yasir Shah finished with three wickets each for Pakistan.
Hafeez, who also picked up two wickets, added 50 for the opening wicket with debutant left-hander Sami Aslam (20), who was given out caught behind off Taijul Islam after Mushfiqur successfully reviewed the umpire's not-out verdict.
Mushfiqur, however, dropped Azhar on 11 and 28, the second one forcing him to leave the field with an injured finger.
Hafeez, who successfully overturned the umpire's caught behind decision against him on 13, brought up his eighth test century with two consecutive fours off paceman Rubel Hossain before taking off his helmet and kissing the turf to celebrate the mark.
The 34-year-old right-hander had scored 96, 101 not out, 197 and 24 in his last four innings in tests against New Zealand in United Arab Emirates in November.
Hafeez hit 12 fours and two sixes in his 179-ball knock and added 177 for the unbroken second wicket with Pakistan's ODI captain Azhar.
Bangladesh employed eight bowlers but could not find a second breakthrough and are now 105 runs ahead. – Reuters
Original source: Hafeez ton puts Pakistan in control