Pakistan overcame a familiar attack of batting nerves to beat Sri Lanka by three wickets in a see-saw Group B game.
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, collapsed to 162 for seven.
But an unbroken stand of 75 between Sarfraz, dropped twice on his way to 61 not out, and Mohammad Amir (28 not out) saw Pakistan complete a thrilling win.
They 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.
Pakistan started their group campaign with a woeful 124-run defeat by arch-rivals India but bounced back to defeat top-ranked South Africa before this success against Sri Lanka.
India will play Bangladesh in Thursday's second semi-final at Edgbaston, with the final at the Oval on Sunday.