Hafeez had played a starring role in the home side's two victories in Sharjah and proved crucial to their hopes on Wednesday as his 113 not out ensured Pakistan comfortably reached their victory target of 226 with 53 balls to spare.
Sri Lanka, having won the toss, slipped to 36 for three at one point and although half-centuries from Kumar Sangakkara and debutant Ashan Priyanjan bolstered their total to 225 all out, it proved insufficient.
It was seamer Umar Gul who did the early damage at the top of the tourists' order.
The 29-year-old struck with his fourth ball when Kusal Perera slapped straight to short cover before he knocked Tillakaratne Dilshan's off-stump back in his next over.
By the time Gul had Dinesh Chandimal caught in the covers, Sri Lanka looked to be sinking without trace.
But Sangakkara and Priyanjan led the recovery, with the latter particularly impressive on debut after hammering dangerman Gul for three fours in an over.
Those moments of all-out attack were rare, though, as the pair accumulated steadily, with Priyanjan bringing up his 50 in the 28th over, a ball before Sangakkara reached the landmark - his 83rd in ODIs.
The veteran fell for 51 off 78 balls in the next over after he was run out at the non-striker's end to end a stand of 89.
Priyanjan thumped two fours off Shahid Afridi soon after but was then bowled for 74 by Junaid Khan after trying to work the left-arm seamer to fine leg with a paddle sweep.
Nuwan Kulasekara was tamely dismissed by Saeed Ajmal, who claimed the first of four victims by taking a return catch despite bowling a full toss.
Sri Lanka captain Angelo Mathews led some brief resistance by hammering Junaid for a four then a six in the same over but he fell for 38 after being trapped in front by Ajmal, who then bowled Sachithra Senanayake with his next ball as the tourists crumpled to 225 all out after 48.5 overs.
Ahmed Shehzad got Pakistan's chase off to a great start with three fours in an over off Kulasekara, whose opening bowling partner Lasith Malinga fared no better as he was hit to the boundary twice by Sharjeel Khan.
Mathews came into the attack in just the sixth over to stem the tide and his decision paid dividends as he bowled Sharjeel with his first ball.
Mathews would have felt aggrieved not to have landed the in-form Hafeez two balls later as the veteran got off the mark with an inside edge for four.
The 33-year-old batsman settled into his task with three fours off Suranga Lakmal before then hammering Malinga for six-four.
The runs continued to flow as Hafeez brought up his 50 off just 39 balls although Shehzad could not emulate his partner, falling six runs short after edging Lakmal to first slip.
Hafeez kept going and brought up his ninth ODI hundred with his 12th four through the leg side.
Sohaib Maqsood proved a capable foil, thumping Dilshan back over his head for six, and the pair continued at pace before Maqsood (46no) hit the winning run in the 42nd over.
- Sports & Recreation
- Kumar Sangakkara
- Umar Gul
- Ashan Priyanjan
- Tillakaratne Dilshan