Pakistan overcame a familiar attack of batting nerves to beat Sri Lanka by three wickets in a see-saw Group B game at Sophia Gardens to set up a Champions Trophy semi-final with hosts England back in Cardiff later this week.
The other semi-final will pit Group B winners India against Group A runners-up Bangladesh at Edgbaston.
Pakistan appeared to have thrown away their victory chance at several points as their batsmen's fallibility before the short-pitched ball prompted an astonishing collapse from 74-0 to 162-7.
But captain Sarfraz Ahmed, who had already distinguished himself with two fine catches behind the stumps, steadied the innings, steering them home to 237-7 in the 45th over with a match-winning innings of 61 from 79 balls.
At the other end, Mohammad Amir provided an equally valuable contribution, taking singles to rotate the strike as he reached an unbeaten 28. Their 75-run partnership was an eighth-wicket record for the Champions Trophy.
"It is an unbelievable feeling. I just said to Amir play your normal game," said Sarfraz who kissed the ground after hitting the winning runs.
Even the captain suffered the occasional rush of blood, however, and was twice dropped on 38 and 40 by Thisara Perera and substitute fielder Seekkuge Prasanna off a disconsolate Lasith Malinga. The same bowler had also seen opener Azhar Ali spilled by Asela Gunaratne in his first over.
For a while it hardly seemed to matter as excellent bowling from Malinga (1-52) and Nuwan Pradeep (3-60) ensured a regular procession of batsmen from the wicket.
Earlier, Sri Lanka had suffered a collapse of their own as superb left-arm pace bowling from Amir and Junaid Khan reduced Sri Lanka from 161-3 to 167-7 in four devastating overs.
Charging in with great pace and guile, Amir removed danger man Angelo Mathews for 39 and opener Niroshan Dickwella, whose 73 had provided the base to Sri Lanka's innings.
Junaid (3-40) added to the mid-order carnage as Sri Lanka, who had begun breezily to reach 82-1 from 14 overs, could do little more than see out their overs to post a disappointing 236 all out, with Hasan Ali also weighing in with 3-43.
Sri Lanka's total always looked below par, particularly after Pakistan pinch-hitter Fakhar Zaman smashed a quickfire 50 in 11 overs. But his departure without adding another run set the nerves jangling and by the end Pakistan were limping home.
Pakistan's semi-final will be their first meeting with England in a 50-over tournament since 2003 and their first knockout clash since they won the 1992 World Cup final.
-Reuters