The Mexicans lost 2-1 Wednesday against already-qualified Portugal but still advanced because Angola was held to a 1-1 draw by Iran in the other Group D match.
Later, the Netherlands and Argentina played to determine the winner of Group C and who will face Portugal on Sunday in Nuremberg. Serbia-Montenegro and Ivory Coast, who have both been eliminated, also played.
Portugal played without several starters in Gelsenkirchen since it had already qualified for the second round for the first time in 40 years.
Kikin headed in a corner kick to put Mexico back in the game before halftime.
Portugal coach Luiz Felipe Scolari spared five key players for this match. The absences included playmaker Deco, winger Cristiano Ronaldo, and all-time top scorer Pauleta. Mexico started the match with six defenders.
Even so, the Portuguese extended their unbeaten run to 17 international games, during which they have allowed just six goals.
"Things couldn't be better," Scolari said. "This was as tough a game as we had expected, but I asked my players today to make it hard for me to pick my team for the next round, and they did that."
Mexico had lost only two of its last 12 games against European opposition in World Cup matches. The last time Mexico played at a World Cup and failed to advance to the second round was 1978. The team didn't play at the 1982 and 1990 World Cups, and reached the quarterfinals in 1986.
"We started very well," Mexico coach Ricardo Lavolpe said. "We had control for long periods but when you have the ball you have to score, and we even missed a penalty."
Needing Mexico to lose and in order to make up a three-goal difference, Angola played attacking soccer for much of the match in Leipzig.
Flavio, who came on as a substitute for Angola captain Fabrice Akwa, scored his team's first goal of the World Cup in the 60th minute. He broke free from Kaabi Hossein in the penalty box and headed a cross from Ze Kalanga over goalkeeper Ebrahim Mirzapour.
Sohrab Bakhtiarizadeh equalized in the 75th to give Iran its first point and end Angola's hopes of advancing.
Bakhtiarizadeh jumped over Love and headed a corner kick from Mehdi Mahdavikia just inside the post with no defenders guarding the area. Goalkeeper Joao Ricardo yelled at his defenders after the score in apparent frustration.
The Black Antelopes had the first real opportunity in the 12th minute with Mateus shooting over the crossbar from inside the penalty area.
Iran replied two minutes later when Ricardo smothered a low shot from Ferydoon Zandi. Ricardo stopped a free kick by Ali Daei in the 24th from the edge of the area, and his resulting header went over the bar.
Iran's best chance came in the 27th minute, when defender Mendonca stopped Zandi's header in the goalmouth.
"When we arrived [in Germany] with the team, the first idea that we would suffer many goals didn't happen," Angola coach Luis Oliveira Goncalves said. "With two draws ... the people of Angola can be very, very proud."
Also, Michael Owen will miss the rest of the World Cup after tearing the anterior cruciate ligament in his right knee.
The England striker was injured Tuesday in the second minute of his team's 2-2 draw with Sweden in Cologne. Owen had a scan on his knee Wednesday near England's team base in southern Germany and left for England later in the day.
Munich police said they had arrested four drunken fans for celebrating Germany's 3-0 World Cup win over Ecuador with the "Sieg Heil" Hitler salute.
In London, hundreds of children who fell victim to a World Cup ticket scam should get their chance to attend the tournament after all, thanks to Britain's prime minister and soccer's top official.
Moved by an appeal from Prime Minister Tony Blair, FIFA president Sepp Blatter rustled up 350 tickets to a quarterfinal match that could involve England after the children were turned away last week when bogus agencies failed to come up with their tickets.