The tourists batted the entire day to move from their overnight score of 227 for one to 537 for five by stumps, a lead of 205 runs over Bangladesh's first innings total of 332.
Hafeez, who started the day on 137, surpassed his previous best of 197, made in Pakistan's previous Test against New Zealand in Sharjah last November.
The 34-year-old all-rounder hit 23 boundaries and three sixes before being dismissed just before tea, gloving a sweep off Shuvagata Hom to Mohammad Mahmudullah at leg-slip.
Hafeez said he was relieved to overcome the poor form that had dogged him in the preceding one-day series which Pakistan lost 3-0.
"I was under pressure and I knew I had to do something to regain my confidence," the 41-Test veteran said. "The team needed a positive innings and I am happy that I was able to provide that.
"I am not sure if this was my best innings, but a double hundred is always special for any batsman in the world."
Azhar Ali carried his overnight score of 65 to 83 when he was bowled by off-spinner Shuvagata to end a 227-run partnership for the second wicket with Hafeez.
