After claiming 2-20 from 10 overs as Sri Lanka totaled 135-8 from 42 overs, Hafeez top-scored for Pakistan with 37 as the visitors eclipsed the target in 34.1 overs to win on the Duckworth-Lewis Method.
Umar Akmal (36 not out) and Misbah-ul-Haq (30) also contributed for Pakistan at Pallekele International Cricket Stadium.
Earlier, Umar Gul took 3-24 and Mohammad Sami 3-19 to rip through Sri Lanka's batting line-up.
Lahiru Thirimanne hit an unbeaten 42 and put on a 50-run stand for the eighth wicket with Nuwan Kulasekara (18).
There are four more matches in the series.