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.
Pakistan’s one-day success follows their 2-1 victory over Sri Lanka in the preceding Test series under Misbah-ul Haq’s captaincy.
Skipper Azhar Ali said the series win was the team’s gift to the people of Pakistan who celebrated the holy Muslim festival of Eid last week.
“This is our Eid gift to our fans,” he said. “With the Champions Trophy qualification in mind, every game becomes important, so we want to win the final game also.
“Credit is due to the bowlers who kept the pressure on the Sri Lankan batsmen. And then Shehzad and Hafeez batted so well to bring us victory.”
Sri Lanka are assured of taking part in the Champions Trophy, but their lacklustre display did not do justice to the former world champions.
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.
Shehzad fell five runs short of his fourth one-day century when he cut seamer Suranga Lakmal to a diving Kusal Perera at third man. He hit 12 boundaries and a six.
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.
Sri Lanka’s captain Angelo Mathews said he was disappointed by the loss because his team did not put enough runs on the board despite a good start.
“There was no real penetration in our bowling attack,” he said. “We also did not take the chances that came our way. But we are determined to end the series on a winning note.
“We need to play positive cricket and get out of the hole we have dug ourselves in.”
Lahiru Thirimanne top-scored with 90 for Sri Lanka after Mathews won the toss for the first time on Pakistan’s current tour and elected to bat.
The left-hander put on 109 for the second wicket with Tillakaratne Dilshan (50) after Perera had been dismissed by Mohammad Irfan off the second ball of the match.
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.
The fifth match will be played in Hambantota on Sunday.
Full scoreboard of the fourth one-day international between Pakistan and Sri Lanka at the Premadasa stadium in Colombo on Wednesday:
K. Perera c Imad b Irfan 0
T. Dilshan b Imad 50
L. Thirimanne c Shehzad b Yasir 90
A. Mathews c Yasir b Rahat 12
D. Chandimal c Yasir b Irfan 20
A. Priyanjan c Hafeez b Anwar 18
M. Siriwardana c Rizwan b Anwar 19
S. Pathirana run out 14
L. Malinga c Rizwan b Irfan 17
S. Lakmal not out 1
N. Pradeep not out 0
Extras: (b4, lb1, w8, nb2) 15
Total (for nine wickets, 50 overs) 256
Fall of wickets: 1-0 (Perera), 2-109 (Dilshan), 3-143 (Mathews), 4-170 (Chandimal), 5-186 (Thirimanne), 6-215 (Siriwardana), 7-228 (Priyanjan), 8-243 (Pathirana), 9-252 (Malinga).
Bowling: Irfan 10-0-50-3 (nb2, w2), Anwar 7-0-41-2 (w4), Rahat 7-0-39-1 (w2), Yasir 10-0-50-1, Azhar 2-0-13-0, Imad 10-0-43-1, Malik 4-0-15-0.
Azhar Ali c sub (Senanayake) b Malinga 33
Ahmed Shehzad c Perera b Lakmal 95
Mohammad Hafeez c Chandimal b Siriwardana 70
Sarfraz Ahmed not out 17
Shoaib Malik not out 29
Extras: (b4, w9) 13
Total (for three wickets, 40.5 overs) 257
Fall of wickets: 1-75 (Azhar), 2-190 (Shehzad), 3-213 (Hafeez).
Bowling: Malinga 9-2-46-1, Lakmal 8-0-50-1 (w3), Pathirana 10-0-81-0, Pradeep 2.2-0-9-0 (w1), Mathews 2.4-0-9-0 (w2), Siriwardana 5.5-0-28-1, Dilshan 3-0-30-0 (w3).
Pakistan won by seven wickets, lead 3-1 in five-match series
Toss: Sri Lanka
Umpires: Raveendra Wimalasiri (SRI) and Rod Tucker (AUS)
TV umpire: Ian Gould (ENG)
Match referee: Javagal Srinath (IND)