With each side winning once so far in the five-match series, 33-year-old Hafeez scored an unbeaten 140 to add to the century he scored in the opening game.
Sri Lanka captain Angelo Matthews won the toss at the Sharjah Cricket Stadium in the United Arab Emirates and chose to field, with the early wicket of opener Sharjeel Khan suggesting it was a good decision.
Khan had scored just two runs from 11 deliveries before being bowled by Nuwan Kulasekara at the end of the third over.
That brought Hafeez to the crease early on and he and Ahmed Shehzad set about building a competitive total for the tourists.
The duo added 160 runs for the second wicket until Shehzad was run out following a superb piece of fielding by Lasith Malinga.
The seamer reacted quickly to Hafeez pushing his delivery away and collected the ball on his follow-through, turning and throwing at Shehzad's wicket as the opener scurried back in vain.
Sohaib Maqsood was the next man in and he added a run-a-ball 21 until being caught by Sachithra Senanayake as he tried to smash Thisara Perera to the rope.
Skipper Misbah-ul-Haq wasted little time in attacking the Sri Lankan attack as he looked to score quickly and the 39-year-old reached 40 in just 26 balls until becoming Senanayake's second victim, holing out to Dimuth Karunaratne in the 46th over.
Malinga then bowled Shahid Afridi for just two before Umar Akmal weighed in with an unbeaten 23 to bolster the total.