Mohammad Hafeez chipped in with 70 as the tourists surpassed Sri Lanka's 256-9 in the 41st over at the Premadasa stadium to take a decisive 3-1 lead in the series.
The series win kept Azhar Ali's Pakistan in contention for a place in the eight-nation Champions Trophy in England in 2017.
Pakistan are two points ahead of the West Indies at number eight in the rankings, but both teams are due to play a tri-series in Zimbabwe next month that will determine the final spot.
Sri Lanka are assured of taking part in the Champions Trophy, but their lacklustre display did not do justice to the former world champions.
More From This Section
Shehzad and Azhar put Pakistan on the road to victory with an opening stand of 75 in 11 overs before the skipper was removed by sling-arm fast bowler Lasith Malinga for 33.
Hafeez helped Shehzad build on the fine start by adding 115 for the second wicket, but Sri Lanka hit back to remove both batsmen in the space of 23 runs.
Hafeez was caught behind by Dinesh Chandimal off spinner Milinda Siriwardana to leave Pakistan on 213-3, but Sri Lanka's recovery came too late.
Shoaib Malik hit a 16-ball 29 and ended the match by lofting Siriwardana over mid-wicket for his fourth six. Sarfraz Ahmed remained unbeaten on 17.
Earlier, Lahiru Thirimanne top-scored with 90 for Sri Lanka after skipper Angelo Mathews won the toss for the first time on Pakistan's current tour and elected to bat.
Thirimanne missed his fifth one-day century when he swept leg-spinner Yasir Shah to deep square-leg, where Shehzad picked up a low catch to make amends for a dropped catch in the bowler's previous over.
Besides Thirimanne and Dilshan, none of the other top-order batsmen settled in as Mathews fell for 12 and Dinesh Chandimal was dismissed after making 20.
Tailender Malinga smashed 17 off 13 balls at the end to ensure Sri Lanka crossed the 250-run mark.