Pakistan beat Bangladesh by 94 runs at Lord's for a fourth straight win hours after it missed out on the Cricket World Cup semifinals.
Going to the last four instead is New Zealand, a team Pakistan beat by six wickets last week.
Pakistan secured fifth place and finished on 11 points, the same as fourth-placed New Zealand. Both team had five wins but the Black Caps advanced with a much superior net run-rate.
To reach the semis, Pakistan had to win by an unprecedented score. It didn't take on the challenge and finished on 315-9 with Imam-ul-Haq scoring a 100-ball 100 and Babar Azam 96 in 98. The updated maths meant, to advance to the semis, Pakistan had to bowl out Bangladesh for seven or less, and that equation died in the second over of the chase.
Powered once more by the brilliant Shakib Al Hasan (64 runs in 77 balls), Bangladesh ended on 221 all out with 19-year-old Shaheen Afridi swinging the ball and taking 6-35, the best figures by a Pakistan bowler in World Cup history. He ended with 16 wickets in five matches.
Shakib finished his tournament with a total of 606 runs from eight innings, the third highest ever in World Cup history, behind India's Sachin Tendulkar (673 in 11 innings) and Australia's Matthew Hayden (659 in 10). Shakib averaged 86 runs an innings.
But his total could be overtaken after Saturday's two games involving three openers: India's Rohit Sharma and Australia's David Warner and Aaron Finch.
New Zealand joined Australia, India and England in the last four. Who meets who next week will be decided overnight.
Bangladesh's Mustafizur Rahman returned 5-75 to move to 20 wickets, four behind tournament leader Mitchell Starc.
The huge score Pakistan required looked unlikely despite a ton from opener Imam, who was out in rare fashion by hitting his own wicket two balls after his maiden World Cup century.
Babar hit 11 boundaries, four more than Imam.
Pakistan captain Sarfaraz Ahmed retired hurt on two but bravely returned for the last ball of the innings and hit a single to deny Mustafizur a hat trick.
Babar scored 474 runs in the group stage, a record by a Pakistan batter at a single World Cup. He came into the game needing 60 to overtake Javed Miandad's 437 total in 1992.
- AP