The miraculous triumph in Mumbai, which looked impossible when Australia fell to 7-91, confirms Pat Cummins' men will face South Africa in the semi-finals next week.
Chasing 292 runs for victory in Mumbai, Australia capitulated to 7-91 following a fast start from the Afghan pace attack and looked a serious chance to fall to a shock upset.
But Australia's last recognised batter Maxwell's hit an unbeaten 201 from 128 balls, partnering with captain Pat Cummins (12no off 68 balls) to stage a rescue mission on his return from a freak golfing accident that had left him concussed last week.
Glenn Maxwell needed treatment during his epic match-winning World Cup double hundred.
Maxwell survived a dropped catch and successfully overturned the umpire's call of LBW in the 22nd over and seemed to take the pair of near-misses as a sign to throw caution to the wind.
Shortly after bringing up his second century of the tournament in the 33rd over, Maxwell began battling a back problem that began to significantly hamper his ability to run.
The Afghan attack, which had dismissed every other specialist batter for under 25 runs apiece, had no answers as 'The Big Show' lived up to his billing - even on one leg.
At one stage, Maxwell collapsed to the ground, apparently cramping all over, and Adam Zampa lurked at the boundary rope in case the veteran needed to retire hurt.
Maxwell did no such thing and in the 47th over, Maxwell belted his eighth six to eclipse Shane Watson's unbeaten 184 from 2011 as the best individual ODI innings by any Australian in history.
With his 10th six from the penultimate ball of the 47th over, Maxwell sealed the unlikeliest of wins with three overs to spare.
Mitch Marsh (24) was Australia's next-most prolific scorer as Australia pulled off their biggest successful run chase at the ODI World Cup, and pieced together the biggest eighth wicket-partnership in the format's history.
Marcus Stoinis thought he had made a great catch to dismiss Rashid Khan but the TV umpire disagreed.
The five-time World Cup champions were shaky early on in reply to Afghanistan's highest-ever World Cup total (5-291), posted largely thanks to a maiden World Cup century from Ibrahim Zadran (129no)
Opener Travis Head fell for a duck in the second over from Naveen-ul-haq's bowling (2-47).
Azmatullah Omarzai came within an inch of claiming Afghanistan's first-ever ODI hat-trick when he bowled in-form opener David Warner (18) and then had Josh Inglis (0) caught behind.
As the reality of a World Cup disaster set in, so too did panic; Marnus Labuschagne (14) was run out with a direct hit after being slow to react to Maxwell's call for a single, before Marcus Stoinis burned a review for LBW and went on six.
But everything changed when Maxwell got his eye in.
Earlier, the Australians found wickets hard to come by on a deck that has been unkind to the bowlers so far this tournament.
Spinner Adam Zampa (1-58) could not reprise the trickery in the middle overs that has been vital to Australia's five-game winning streak.
Ever-reliable Josh Hazlewood (2-39) had the most luck, while Maxwell (1-55) broke Rahmat Shah's 83-run partnership with Ibrahim Zadran (129) and forced Afghanistan back into their shells.
Save for during a cameo from Azmatullah Omarzai (22 runs off 18 balls), the Afghan innings was a conservative one until after Zadran brought up his ton.
After reaching triple figures, the 21-year-old forged a 58-run partnership with Rashid Khan across the final four-and-a-half overs, helping Afghanistan to what appeared a very competitive total.