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