Skipper Sarfraz Ahmed (61) cracked a gritty fifty as Pakistan notched up a three-wicket win over Sri Lanka in their must-win Group B match to enter the semi-finals of the ICC Champions Trophy in Cardiff on Monday.
Pakistan will meet Group A toppers England in the first semi-final on Wednesday at the same venue.
Chasing a modest 237 to win, opener Fakhar Zaman (50) slammed a 36-ball 50 at the top but Pakistan suffered an inexplicable collapse to slip to 162-7.
Finally, it was Sarfraz, who played a resolute captain's knock to take Pakistan home. The wicket-keeper batsman shared an unbeaten 75-run stand with Mohammad Amir (28) for the 8th wicket as Pakistan overhauled the target with 31 balls to spare.
Sri Lankan seamers, led by Nuwan Pradeep (3/60), produced a disciplined bowling performance but some sloppy fielding, which included two drop catches of Sarfraz, cost them the match.
Chasing a modest 237 to win, Fakhar gave Pakistan a flying start as he alongwith Azhar Ali shared a 74-run opening partnership in 11.1 overs.
Fakhar blasted eight boundaries and one six to score his fifty but he top-edged a Nuwan Pradeep delivery next to Gunaratne at fine leg as Pakistan lost their first wicket in the 12th over.
Pakistan then lost three quick wickets -- Babar Azam (10), Mohammad Hafeez (1) and Azhar Ali (34) to slip from 92-1 to 110-4 in the 20th over.
Shoaib Malik (11) and Imad Wasim (4) also coudn't last long and perished in consecutive overs as Pakistan slumped to 137-6 in 25.4 overs.
Skipper Sarfraz Ahmed, who was dropped twice in the 39th and 41st over off Malinga, made good use of the chances to produce a match-winning innings and in company of Amir took the team home.
Earlier, fast bowlers Mohammed Amir and Junaid Khan combined to polish off the middle order, helping Pakistan bowl out Sri Lanka for 236 in a virtual quarter-final of the ICC Champions Trophy.
Sri Lanka looked set for a big score after being asked to bat in the final Group B match but Amir (2/53) and Junaid (3/40) scripted a turnaround with fiery spells.
Hasan Ali (3/43) was another Pakistani paceman who made an impact at the start of the innings.
Opener Niroshan Dickwella (73) and skipper Angelo Mathews (39) had put on a display of resolute batting before Amir scalped the latter to trigger a collapse at SophiaGardens.
Amir and Junaid took two wickets each in the space of 3.2 overs as Sri Lanka lost four wickets, including the well-set Mathews and Dickwella, for six runs.
Lower-order batsmen Suranga Lakmal (26) and Asela Gunaratne (27) offered dogged resistance to take Sri Lankan innings close to the 250-run mark. They added 46 crucial runs for the eighth wicket.
At the start, Danuhska Gunathilaka (13) was scalped early by Junaid but Dickwella and Kusal Mendis (27) stitched a 56- run stand to keep Sri Lanka going.
Things looked settled for the Island nation before Hasan Ali came up with a fiery spell, in which he troubled Mendis with pace and bounce before eventually bowling him out.
It brought Dinesh Chandimal to the crease but his stay was reduced to just two balls as the batsman dragged one from Fahim Ashraf onto his stumps, going for a drive.
Two wickets in three balls, however, did not bother Sri Lanka much as Dickwella remained solid at the other end and soon completed his half-century with a single off Mohammed Hafeez.
Skipper Mathews supported his colleague with a patient knock. The two batsmen rotated the strike quite easily, which not only kept the scoreboard ticking, but also put pressure back on Pakistan.
Frustration grew among Pakistan players with Mathews and Dickwella raising a resolute 78-run stand for the fourth wicket in 16.1 overs.
Amir was brought into the attack and he delivered with his second ball, getting rid of Mathews, who miscued a shot and dragged it onto his stumps.
It was the first wicket of the tournament for Amir and it came at a crucial time for Pakistan. Junaid sent back new man Dhananjaya de Silva (1) and Amir returned to dismiss Dickwella, who fell to a sensational low catch by wicketkeeper Sarfraz Ahmed.
Junaid saw the back of Thisara Perera to rattle the Lankan innings.
The truth about Dhawan's SRK touch celebration style
In order to win, you have to say things that hurt: Kohli
Kumble to stay India coach for WI tour: COA head Vinod Rai
How Bumrah became Kohli's 'go to man'
Hurt but a defiant De Villiers wants to stay on as captain