Pakistan hammered Bangladesh by 94 runs at Lord's but failed in their highly unlikely task of pipping New Zealand to the last World Cup semi-final place.
The 1992 winners needed victory by a record margin of at least 308 runs to finish fourth on a better net run-rate.
An Imam ul-Haq century and 96 from Babar Azam saw them post 315-9 before they dismissed Bangladesh for 221.
Shakib Al Hasan top-scored with 64 for the Tigers but seamer Shaheen Afridi (6-35) produced a match-winning spell.
Pakistan could not reach the semi-finals once Bangladesh reached 8-0 in the second over of their chase, confirming New Zealand in the last four with Australia, India and England.
England will finish third and New Zealand fourth, with the group winners to be decided on Saturday.
Leaders Australia will top the group if they beat South Africa at Old Trafford (13:30 BST) - but if the defending champions lose, India can overtake them by winning against Sri Lanka at Headingley (10:30).
Realistically, Pakistan knew their tournament was all but over before a ball was bowled at headquarters, even though captain Sarfaraz Ahmed said: "If Allah helps then miracles can happen."
There remained the smallest of chances a record-breaking one-day international victory could see them sneak into the semi-finals on net run-rate.
The minimum score they needed to stand any theoretical chance was 308, but even that would have meant Bangladesh needing to be bowled out for nought.
In the end, they stuttered their way to 315-9, despite Imam and Babar providing the platform with their 157 partnership off 151 balls for the second wicket. But when the latter was dismissed hit wicket a ball after recording his seventh one-day international century, 246-2 in the 42nd over was perhaps not fully capitalised upon.
Imad Wasim (43) did launch a counter-attack with some lusty blows despite striking skipper Sarfaraz on the arm at one stage, forcing him to retire hurt.
Ultimately, neither that nor the injury would cost Pakistan, with the wicketkeeper able to resume his innings off the last ball, before adding a catch and a stumping in the field.
Shaheen's figures were both his first five-wicket haul in ODI cricket and the best figures by a Pakistan bowler in a World Cup match.
The 19-year-old left-armer had Shakib caught behind and then removed the lower order with a series of fast yorkers to claim the best figures of the tournament so far.
He is one of a number of impressive young players in this Pakistan team, including Imam, 23, leg-spinner Shadab Khan, 20 and 24-year-old Babar, who could be key members of the side as they build towards the next World Cup.
All-rounder Shoaib Malik, 37, confirmed he will now retire from ODI cricket, although he will continue to play in Twenty20s.
Bangladesh came to this World Cup as dangerous underdogs and caused a couple of upsets along the way.
But amid memorable victories against South Africa and West Indies, defeats such as this, where standout individual performances have lacked support, have been disappointing.
Here Mustafizur Rahman took 5-75 to become the second-highest wicket-taker at the tournament on 20 behind Australia's Mitchell Starc with 24.
Then with the bat, Shakib reinstated himself at the top of the run-scoring charts on 606 with his seventh score of 50 or more in this competition, including two centuries, which equalled Sachin Tendulkar's record for India from 2003.
Their coach Steve Rhodes, the former Worcestershire and England wicketkeeper, will no doubt take the positives from their victories - but will also be aware what might have been in some of their closer-fought defeats. Pakistan coach Micky Arthur: "I do feel net run-rate needs to be looked at. One really poor game and you're really battling to recover.
"I'd like it to be number of wins and then head-to-head and then net run-rate in the future that determines places when points are level."
Pakistan captain Sarfaraz Ahmed: "Unfortunately we played very good cricket in the last four matches but we have not qualified.
"Only the one match will cost us in the whole tournament (the heavy defeat by West Indies). We played very good cricket. The way we responded after India, we played very well in all three - batting, fielding and bowling.
"The way Shaheen is bowling is very good. Today it was one of the best bowling performances I have seen in a long time."
Bangladesh captain Mashrafe Mortaza: "The whole team is disappointed, but on the other hand with the way we've played, we could've finished higher in the table.
"A few things have been very good, but others have not been very good. Little things in games do make a huge difference."
On Shakib Al Hasan's performances in the World Cup: "He has been absolutely brilliant in this tournament and I feel sorry for him that the team have not been able to back up those performances.
"I think he has put in one of the best performances in the history of this World Cup and hopefully next time the boys will step up with him."
Source: BBC Sports