Pakistan needed just 20.5 overs to chase down a target of 103, with skipper Misbah-ul-Haq completing the victory in fine style by smashing a six.
Bangladesh had earlier mounted some resistance in their second innings but were eventually dismissed for 234, as they paid the price for a collapse late on day four.
Hafeez would make Bangladesh pay for the missed chance, however, as he went on to score 47 before being caught by Shahadat Hossain off Shakib Al Hasan to leave Pakistan on 70-2.
Azhar Ali took Pakistan to the brink of victory by adding 34 but he could not quite see his innings through to the finish as he was bowled by Elias Sunny with two runs of the target remaining.
But Misbah (six not out) soon took his side over the line, while Younus Khan was also unbeaten on 16 when the winning runs were scored.
Bangladesh had earlier kept their slim hopes of a draw alive during a fog-shortened morning, but their fate was sealed when they lost their last five wickets for just 22 runs after lunch.
Hossain and Mushfiqur Rahim had put on 117 for the sixth wicket but once the stand was broken, Bangladesh offered little resistance.
Abdur Rehman made the breakthrough with a straight delivery that fooled Hossain and struck the stumps, dismissing him for 79 with Bangladesh on 212-6.
Rahim soon followed for 53, with Rehman again the bowler, as he mistimed a shot straight into the hands of Saeed Ajmal at mid-off.
Rehman added the scalp of Shahadat, thanks to a superb one-handed catch in the slips from Younus, to finish the innings with figures of 4-51.
Saeed Ajmal also grabbed a couple of wickets, taking his tally for 2011 to 50, including the final scalp of Robiul Islam, who wandered down the track to give Adnan Akmal an easy stumping.
And there would still be time for Pakistan to wrap up the victory, completing a resoundingly successful tour, which also included a 3-0 sweep in the one-day series and a win in the sole Twenty20.