The 34-year-old right-hander smashed 122 off 129 balls and was ably supported by Sohaib Maqsood (73) and debutant opener Sharjeel Khan (61) as Pakistan, who won the toss, capitalised on a mirror-like flat Sharjah stadium pitch.
Hafeez, whose place was in danger over poor form after only 147 runs in the last eight one-dayers, hit seven boundaries and four sixes in his seventh one-day hundred.
He hoisted paceman Suranga Lakmal over long-on for a six to reach the three-figure mark against some hapless Sri Lankan bowling.
Maqsood was run out after hitting four sixes and two boundaries during an entertaining 68-ball knock.
Also Read
Shahid Afridi, promoted to fifth in the batting order, played a fiery 12-ball knock of 34 studded with three sixes and two boundaries as Pakistan mustered 103 in the last ten overs.
Pakistan had a good start of 35 by the seventh over before Lakmla trapped Ahmed Shehzad leg-before for 11.
Hafeez and Sharjeel raised the scoring rate, with the opener hitting two sixes and a four off paceman Thisara Perera in the 13th over and then hit spinner Sachitra Senanayake for a boundary towards long-off to bring up his half-century off 46 balls.
Lakmal finished with the best bowling figures of 2-73.