Hafeez's fourth score of 50-plus in the last six one-day innings built on a 93-run opening stand between Ahmed Shehzad (44) and skipper Azhar Ali (49) after Pakistan chose to bat.
Sarfraz, promoted to number four from lower down the order, justified the captain's faith with seven boundaries in his 74-ball knock at the Premadasa stadium.
The gutsy wicket-keeper put on 72 for the third wicket with Hafeez and 61 for the fourth with Shoaib Malik to boost the total, before he was run out in the 45th over.
The pair smashed 21 runs in the last over bowled by Lasith Malinga to leave Sri Lanka chasing the highest total in the series so far.
Also Read
The five-match series is level at 1-1 after Pakistan won the opening match in Dambulla last Saturday and Sri Lanka took the second in Pallekele on Wednesday.
Hafeez, 34, had been banned from bowling for a year by the International Cricket Council on Friday after his action was ruled to be illegal -- for the second time in the last eight months.
While Sri Lanka fielded an unchanged side, the tourists replaced batsman Babar Azam with debutant left-arm spinner Imad Wasim to bolster the bowling.
Ninth-ranked Pakistan need a series win to remain in contention for a place in the eight-nation Champions Trophy in England in 2017.
Sri Lanka, currently ranked fifth, are assured of taking part in the tournament.