The 33-year-old right-hander smashed a career best unbeaten 140 to steer Pakistan to an imperious 326-5 before Hafeez the bowler took 2-35 to dismiss Sri Lanka for 213 in 44.4 overs at Sharjah stadium.
The win gives Pakistan a 2-1 lead in the five-match series. Hafeez accounted for the dangerous Dinesh Chandimal (36) and Seekkugge Prasanna (22) in an incisive spell to thwart any hopes Sri Lanka had harboured.
Paceman Umar Gul, playing his first match since March this year after a knee operation, gave Pakistan a sound start by dismissing Kusal Perera (seven) and Dimuth Karunaratne (nought) in his first spell of five overs and then had the last man Lasith Malinga to finish with 3-19.
Opener Tillakaratne Dilshan hit ten boundaries in an aggressive 62-ball knock of 59 but fell to Shahid Afridi as the Sri Lankan innings fell apart.
Kumar Sangakkara also hit a six in his 14 before he fell to paceman Junaid Khan who took 2-40. Skipper Angelo Mathews chipped in with 44 but his dismissal signalled the end.
Winning captain Misbah-ul-Haq said he was happy with the total. "I am really happy at this win," said Misbah. "We were happy to bat first and Hafeez and Ahmed Shehzad (81) gave us an ideal platform for a winning total."
Mathews rued his team's batting failure. "We chased well in the first two matches. There was an ideal opportunity today as well but unfortunately we didn't bat well right from the start," said Mathews. Pakistan had once again been helped by Hafeez and Shehzad after they were put into bat.
Hafeez, who hit 122 in the opening game in Sharjah last week, laid the foundations of the innings with opener Shehzad (81) during their second wicket stand of 160 after Pakistan lost Sharjeel Khan for two in the third over.
Hafeez, dropped by Lasith Malinga off leg-spinner Prasanna when 26, took full advantage of the chance and hit 11 boundaries and three sixes in an enthralling knock.
He took a couple off Malinga in the covers to reach his hundred, which came off 119 deliveries, and added a quickfire 75 for the fourth wicket with skipper Misbah who made a rapid 26-ball 40.
Shehzad set the tempo, following his 124 in Pakistan's two-wicket defeat in the second match in Dubai, with an 89-ball knock which had six fours and two sixes.
Shehzad was run out in the 31st over but Hafeez kept one end intact as Pakistan scored 105 in the last ten overs with Misbah also in top form.
Sohaib Maqsood chipped in with a run-a-ball 21, laced with two sixes and a four. Amidst the run-spree, Thisara Perera took 2-58. The remaining two matches will be played in Abu Dhabi on Wednesday and Friday.
Photos: 'Dangal' girls Sanya Malhotra, Fatima Sana Shaikh's dinner outing
Photos: Salman Khan, Daisy Shah spotted at the Mumbai airport
Photos: Rakhi Sawant to play Honeypreet in Ram Rahim biopic
Photos: Arvind Kejriwal asks Kamal Haasan to join politics
Photos: TV actress who played goddesses on the small screen