Australia will face England in a blockbuster World Cup semi-final showdown as the defending champions finished second in the group after an agonising loss to South Africa.
India's win over Sri Lanka meant Australia were leapfrogged in the standings, shortly after Faf Du Plessis' 93-ball century and Rassie Van Der Dussen's one-day international best of 95 had propelled the Proteas to 325 for six.
Despite David Warner's 122, a defiant innings as he and Steve Smith faced South Africa for the first time since the ball-tampering scandal, Australia lost by just 10 runs as they were all out for 315 after 49.5 overs.
At 119 for four a heavy defeat loomed, but Warner's sensational ton and Alex Carey's 85 from 69 balls helped to bring the equation down to 11 from the final two balls at Old Trafford, only for Nathan Lyon to hole out.
That confirmed India as group winners and they will take on New Zealand while Australia are up against the tournament hosts with fitness doubts over Usman Khawaja and Marcus Stoinis.
Mitchell Starc was wayward against the homeward-bound South Africa, coughing up 14 runs in his first over, but finished with two for 59, taking him to 26 wickets for the tournament and equalling compatriot Glenn McGrath's all-time record.
Starc's struggles after South Africa won the toss led to Quinton De Kock and Aiden Markram, opening in place of the injured Hashim Amla, making a blistering start in a 79-run stand.
Both unleashed a series of sumptuous off-side drives, but Markram was stumped on 34 after overbalancing to Lyon, who also snared Quinton De Kock for 52 after an attempted slog ballooned to Starc at short third man.
Van Der Dussen was struck on the helmet by Pat Cummins and was then given a reprieve on four when Carey missed a stumping. It was a rare moment of aggression from the South African in a guarded start.
Du Plessis was doing the bulk of scoring early on and shortly after passing a half-century, he came down the track and clubbed Cummins over his head for six before crunching through the covers for four.
Van Der Dussen, on 24 from 46 balls, accelerated thereafter, planting Maxwell down the ground for six en route to a 69-ball fifty – the seventh time in 14 ODIs he has gone to a half-century.
Du Plessis moved into three figures – South Africa's first century of the tournament – before departing off the very next ball, miscuing Jason Behrendorff to Starc at short third man, ending a 151-run stand with Van Der Dussen.
Starc removed JP Duminy and Dwaine Pretorius while Van Der Dussen was denied a first international century after holing out to Glenn Maxwell at deep midwicket from the last ball of the innings.
Australia were faltering when Aaron Finch drove Imran Tahir to short cover while Khawaja retired hurt because of a problem to his left hamstring, with Smith – jeered on his arrival to the crease – trapped lbw by Pretorius.
De Kock's flick on to the stumps accounted for Stoinis, who also seemed to be struggling with injury, while the South Africa wicketkeeper took a leaping catch after Maxwell had feathered an attempted pull off Kagiso Rabada.
Warner, who should have been run out on nought but survived because Rabada threw to the wrong end, had contributed 67 from a score of 119 for four.
The left-hander gave the business to anything short, pulling Rabada and Chris Morris over deep midwicket for sixes, and he found a willing ally in Carey, dropped on 28 after Imran Tahir spilled a return catch.
Warner went to a run-a-ball hundred with an outside edge for his 12th four while he and Carey took 16 runs from Tabraiz Shamsi in the 37th over.
However, after Carey had gone past a 47-ball fifty, Warner shovelled Pretorius to wide mid-on where Morris took a blinder of a leaping catch, ending a 108-run stand.
Once Carey had departed, slicing to Markram at cover point off Morris, Khawaja came back out and he and Starc took 17 runs from the 48th over but were both bowled by Rabada shortly afterwards.
Lyon then slugged to deep midwicket off the penultimate delivery to end a thriller as South Africa clinched an eighth win over Australia in their last nine ODIs.