Three times champions Italy narrowly avoided joining France and Argentina on a plane home after being outplayed by group winners Mexico but a late equaliser rescued a 1-1 draw on Thursday.
Jared Borgetti appeared to have sealed Mexico's first ever victory over Italy with a moment of blinding skill in the 34th minute when he glanced an angled header into the top corner of the net from a chipped pass by Cuauhtemoc Blanco.
But five minutes from time, substitute Alessandro Del Piero rapped home from close range to rescue Italy from a dispiriting defeat and put them in the second round.
The match ended in farce when both teams, knowing the result in the other game with bottom placed Ecuador beating Croatia 1-0, played keep-ball for the four minutes of injury time.
Italy had few answers to Mexico's dazzling skills on the ball and rarely threatened Oscar Perez's goal until del Piero's goal although, for the second game running, they had two "goals" ruled out by a linesman.
Italy finished the group in second place with four points, three behind leaders Mexico. They will play the winners of group D, South Korea, Portugal or the U.S.
Ironically, Italy drew 1-1 with Mexico in 1994 to qualify through the group stages before losing to Brazil in the final on penalties. Mexico have never beaten Italy in 10 meetings.
The Italians started brightly and Filippo Inzaghi had a goal disallowed in the 13th minute after he had been put in by Francesco Totti.
Three minutes later Totti produced a magnificent back-heeled flick into Christian Vieri's path but the burly striker fired high and wide over the bar.
Totti then missed a great chance from 10 metres out, firing wide after Inzaghi had run at the Mexican defence and slipped the ball into his path.
Vieri blasted a volley straight at Mexico 'keeper Oscar Perez after neat work from Cristiano Zanetti and Totti.
Totti, enjoying his return to a deeper playmaking role, fired a free-kick just wide of Perez's right hand post in the 24th minute as the Italians sought to turn their pressure into a precious goal.
But Borgetti rose above Paolo Maldini and looped his header over a stationary Gianluigi Buffon in the Italy goal after a stunning build-up to put the Mexicans ahead.
Five minutes after the restart Totti put Inzaghi through on goal but the Italy striker hesitated allowing Perez to push the ball away.
Then the Mexicans went close to a second when Jesus Arellano saw a shot cleared off the line by Fabio Cannavaro, after a smart exchange with Blanco.
Italy coach Giovanni Trapattoni replaced Inzaghi with Vincenzo Montella as his side desperately sought a goal.
Montella had the ball in the net after another Totti through ball, but the linesman had flagged for offside well before the substitute slotted home.
Once more Totti provided an opening in the 72nd minute with a first-time pass over the top for Vieri but his touch let him down and Perez was able to clear the danger.