Pakistan, who moved ahead of England to fourth in the table, now need to win their final match against Bangladesh on Friday and hope other results go their way to advance to the World Cup semi-finals.
All-rounder Imad Wasim's unbeaten 49 guided Pakistan to a thrilling three-wicket victory over Afghanistan in Leeds on Saturday, maintaining their hopes of reaching the World Cup semi-finals.
Chasing a target of 228, Pakistan lost opener Fakhar Zaman for a duck on the second ball of the innings when he was trapped leg-before by off-spinner Mujeeb Ur Rahman.
Babar Azam, who scored his maiden World Cup century in Pakistan's win over New Zealand earlier this week, combined with Imam-ul-Haq to stabilise the innings with a steady 72-run partnership.
Off-spinner Mohammad Nabi removed the pair to expose the middle order, before Mohammad Hafeez and Haris Sohail fell cheaply to leave Pakistan reeling at 142-5.
Captain Sarfaraz Ahmed (18) and Shadab Khan (11) were run-out to set up an intense finale but Wasim and Wahab Riaz (15) ensured there were no further hiccups as they chased down the target with two balls to spare.
"When I went in they were bowling brilliantly but I just hung in there. We wanted to bat out the 50 overs and see," Wasim, who was named man-of-the-match, said.
"Thank you to the crowd, it feels like home here. They gave us a boost in confidence. Win our next game and we'll see what happens. Now we believe we can win from anywhere."
Earlier, Pakistan fast bowler Shaheen Afridi claimed four wickets to restrict Afghanistan to a modest 227 for nine from 50 overs on a flat batting track at Headingley.
Having won the toss and elected to bat, Afghanistan stumbled early on, losing captain Gulbadin Naib and Hashmatullah Shahidi in back-to-back deliveries to Afridi, who produced a blistering opening spell with the new ball.
The very first 4️⃣ wicket haul for a teenager at a @cricketworldcup!— ICC (@ICC) June 29, 2019
Sit back, relax and watch @iShaheenAfridi and @TheRealPCB wreak havoc for the Afghan batsmen #WeHaveWeWill #CWC19 pic.twitter.com/7lO58unjQt
Afridi, playing only his 18th ODI at the age of 19, returned in the death overs to remove Najibullah Zadran and Rashid Khan to finish as pick of the Pakistan bowlers with 4-47.
It was a third consecutive win for Pakistan as their campaign gathers momentum in the business end of the tournament.
"We know it was not an easy target. Their bowlers used the conditions very well. Everyone chipped in, it was good team work," Sarfaraz said.
"We all know that it is not easy to win our last four games, but we go match by match. We will all be watching India v England tomorrow."
Meanwhile, Afghanistan remain winless after eight games, and just as they did against India earlier this month, they came agonisingly close to a memorable victory.
The game was marred by a clash between the supporters of both teams in the stands, with ESPNcricinfo reporting that at least two fans were evicted from the match.
Videos shared on social media also showed fans fighting outside the venue, with the International Cricket Council saying it will take action against "any anti-social behaviour".