Skipper Sarfraz Ahmed (61) cracked a gritty unbeaten fifty as Pakistan survived some tense moments before notching up a thrilling three-wicket win over Sri Lanka in their must-win Group B match to enter the semifinals of the 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) cracked a 36-ball 50 at the top but Pakistan suffered an inexplicable collapse to slip to 162-7.

Source: b'Pakistan seal their path to the semis. ICC'

Finally, it was Sarfraz Ahmed, who played a resolute captain's knock to take Pakistan home. The wicket-keeper batsman shared 75 runs 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 dropped catches off Sarfraz, cost them the match.

Earlier, Fast bowlers Hasan Ali (3/43) and Junaid Khan (3/40) claimed three wickets each, while 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 a dogged resistance to take Sri Lanka's innings close to the 250-run mark. They added 46 crucial runs for the eighth wicket.

Source: b'It was a tough group and Pakistan made it through. ICC'

Chasing a modest 237 to win, Fakhar gave Pakistan a flying start as he and 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.

Feature image source: ICC