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 semifinals of the ICC Champions Trophy.
Pakistan will meet Group A toppers England in the first semifinal 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.
Earlier, Fast bowlers Hasan Ali (3/43) and Junaid Khan (3/40) claimed three wickets each, while Mohammed Amir (2/53) and Fahim Ashraf (2/37) accounted for two wickets to help Pakistan bowl out Sri Lanka for 236 after electing to field.
Opener Niroshan Dickwella (73) and skipper Angelo Mathews (39) added 78 runs for the fourth wicket but Amir and Junaid took two wickets each in the space of 3.2 overs as Sri Lanka lost four wickets for six runs to slip to 167-7.
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.