Sarfraz Ahmed produced a superb captain's innings following a top-order collapse to see Pakistan into the semi-finals of the Champions Trophy with a three-wicket win over Sri Lanka at Cardiff on Monday.
Pakistan, chasing a seemingly modest 237 to win, slumped to 162 for seven.
But Sarfraz's 61 not out and Mohammad Amir's 28 not out saw Pakistan home with 31 balls to spare after they shared an unbroken eighth-wicket partnership of 75.
Man-of-the-match Sarfraz, crucially dropped twice, ended the contest when he uppercut Lasith Malinga for four.
It was his fifth boundary in 79 balls and led the joyous wicket-keeper to run a semi-circle round the ground.
Pakistan will return to Sophia Gardens for a last-four clash with tournament hosts England in Cardiff on Wednesday.
Earlier, Pakistan induced a middle-order collapse as Sri Lanka slumped to 236 all out.
Both Pakistan and Sri Lanka had to win on Monday to join already qualified title-holders India from Group B in the knockout stages of a tournament featuring the world's top eight one-day international sides.
India will play Bangladesh in Thursday's second semi-final at Edgbaston, with the final at the Oval on Sunday.
In what was a 'must-win match' for both sides, Sri Lanka were dismissed for 236 ─ well below the modern-day ODI 'par' total of 300.
And it seemed like it wasn't going to be their day when Pakistan opener Azhar Ali was dropped on nought by Asela Gunaratne at point.
But fellow opener Fakhar Zaman was far more dynamic, hitting three fours in as many balls off the unorthodox Malinga.
In just his second match at this level, the left-handed Fakhar completed a 34-ball fifty.
But, two balls later, he fell for exactly 50 when a top-edged hook off Nuwan Pradeep was caught by Gunaratne at fine leg.
Pakistan, then 92 for one, saw three wickets go down in a hurry.
Babar Azam and Mohammad Hafeez both fell to tame legside catches before Azhar's painstaking 34 ended when he fended at paceman Suranga Lakmal and Kusal Mendis held an awkward catch at a wide slip position.
Shoaib Malik (11) then feathered a catch behind following an attempted pull off Malinga.
Fahim Ashraf thrillingly hooked Malinga over long leg for six but the ODI debutant was run out for a run-a-ball 15 when bowler Thisara Perera deflected a Sarfraz drive onto the stumps at the non-striker's end
Perera drop
Sarfraz was now the key man but Sri Lanka dropped him on 38, when with Pakistan 194 for seven, Thisara Perera at mid-on floored the simplest of catches.
And he was missed again, on 40, when substitute Seekkuge Prasanna dropped a far more difficult chance running in from deep square leg.
In the end, Sri Lanka were made to pay for a poor batting display.
Sent in by Sarfraz, they were making steady progress at 161 for three while top-scorers Dickwella (73) and captain Angelo Mathews (39) were together at the crease.
But the loss of Mathews sparked a middle-order collapse that saw four wickets lost for just six runs as Sri Lanka slumped to 167 for seven.
Only same late tail-order hitting, including Suranga Lakmal's ODI best 26, got Sri Lanka past 200 in an innings where Pakistan pacemen Junaid Khan (three for 40) and Hasan Ali (three for 43) did the bulk of the damage.
All-rounder Mathews, fresh from an unbeaten fifty in Sri Lanka's shock seven-wicket victory over India, drove off-spinner Mohammad Hafeez for six, while Dickwella ended a sequence of 54 balls without a boundary by cover-driving left-arm spinner Imad Wasim for four.
Mathews, however, fell when an inside edge off Mohammad Amir gave the elated left-arm paceman his first wicket of the tournament.
In what turned out to be a brilliant all-round match for wicket-keeper Sarfraz, he held a superb low one-handed catch to dismiss Dickwella after the batsman got an inside edge to Amir.
Teams
Sri Lanka: Niroshan Dickwella (wk), Danushka Gunathilaka, Kusal Mendis, Angelo Mathews (cpt), Dinesh Chandimal, Asela Gunaratne, Dhananjaya de Silva, Thisara Perera, Suranga Lakmal, Lasith Malinga, Nuwan Pradeep
Pakistan: Azhar Ali, Fakhar Zaman, Babar Azam, Mohammad Hafeez, Shoaib Malik, Sarfraz Ahmed (cpt)(wk), Imad Wasim, Fahim Ashraf, Mohammad Amir, Hasan Ali, Junaid Khan