Shaheen Shah Afridi snared six wickets and returned with best ever figures (6/35) by a Pakistan bowler in a World Cup, but his team failed to better their net run-rate in their final group game against Bangladesh which they won by 94 runs at the Lord's on Friday, helping New Zealand qualify for the semifinals as the fourth team.
With fifth-placed Pakistan needing to break the world record for margin of victory in a one-day international, ton-up Imam-ul-Haq and Babar Azam shared a 157-run second wicket stand to guide Pakistan to 315/9 in 50 overs after skipper Sarfaraz Ahmed opted to bat.
It meant Bangladesh needed only eight runs to end Pakistan's hopes of progress and they reached that in the second over.
For Bangladesh, veteran allrounder Shakib Al Hasan racked up his seventh 50-plus score in eight innings in the World Cup with a fluent 64 off 77 balls, his innings laced with six fours. Shakib finished with 606 runs and 11 wickets, the best ever show by an all-rounder at the World Cup.
Promising 19-year old pacer Afridi continued to impress with the ball as he returned career-best figures of 6/35 in 9.1 overs and also became the youngest to take a five-wicket haul in a World Cup.
Afridi took the wickets of Tamim Iqbal (8), Liton Das (32), Shakib, Mahmudullah (29), Mohammad Saifuddin (0) and Mustafizur Rahman (1).
The ball that got Afridi his fifth scalp was a gem of a yorker which Mahmudullah failed to read. Afridi then removed Mustafizur Rahman (1) with a yorker to cap off a dream tournament in which he bagged 16 wickets in just five games.
Pakistan finished level on points (11) with the Kiwis but fell behind on net run rate, while Bangladesh, who were already out of the competition, ended seventh in the 10-team points table with 7 points. Bangladesh were all out for 221 in 44.1 overs.
Earlier, Imam scored a run-a-ball 100 (4x7), his seventh in ODI cricket, while Babar struck 96 off 98 balls, hitting 11 fours, as Pakistan tried hard to get past the 350-run mark but failed in the end despite Imad Wasim's whirlwind 26-ball 43 (4x6, 6x1).
Mustafizur (5/75) took a second consecutive five-wicket haul and was Bangladesh's best bowler along with Saifuddin (3/77).
Pakistan needed to win the toss and bat first in order to still dream of achieving the improbable.
Faced with the challenge of beating Bangladesh by 311 runs after posting 350 or by 316 runs after scoring 400, Imam and Babar played with aggression and were sensible too at the same time. Fakhar Zaman was dismissed early for just 13, taken at point by Mehidy Hasan off Saifuddin.
It was one way traffic from then on as Babar and Imam milked the Bangladesh bowlers all around the park for good-looking boundaries.
The highly-talented 24-year old Babar was unlucky to miss out on his second World Cup hundred as Saifuddin trapped him in front in the 32nd over. Babar immediately asked for a review but replays showed the ball clipping the leg stump.
Imam brought up his hundred with Mohammad Hafeez (27) for company as the pair stitched together a 66-run stand. Just after reaching the three-figure mark, Imam was out hit wicket.
Hafeez also holed out to Shakib in the next over off Mehidy while Haris Sohail too was dismissed cheaply for just 6.
Skipper Sarfaraz Ahmed got injured after being hit on his right arm while standing at the non-striker's end in the 45th over. He tried to carry on but in the end had to retire hurt.
Hard-hitting Wahab Riaz (2) was sent ahead of Shadab Khan but the ploy did not work as Saifuddin yorked him brilliantly. Shadab was also caught and bowled acrobatically by Mustafizur.
In the last 10 overs, Pakistan managed 85 runs riding Wasim's pyrotechnics. In the final over, Mustafizur got the wickets of Wasim and Mohammad Amir off back-to-back deliveries.
Brief scores: Pakistan: 315/9 in 50 overs (Imam-ul-Haq 100, Babar Azam 96, Imad Wasim 43, Mustafizur Rahman 5/75, Mohammad Saifuddin 3/77) vs Bangladesh: 221 all out in 44.1 overs (Shakib Al Hasan 64, Shaheen Shah Afridi 6/35)