Huntelaar, who came on as a 76th-minute substitute for Robin van Persie, scored the winning goal from the penalty spot deep in injury time after Rafael Marquez brought down Arjen Robben in the area.

"You don't know when your chance will come, but it was today, and so you grab it with both hands,'' said Huntelaar, who was making his first appearance at this year's World Cup. "And it was fantastic.''

Giovani Dos Santos gave the Mexicans the lead in the 48th minute, but Sneijder equalized for the Dutch in the 88th.

It was the first time Sneijder, who scored five goals at the World Cup in South Africa, has found the net in Brazil.

Robben has already scored three goals for the Dutch at this year's tournament, but after earning the late penalty, he handed the ball to Huntelaar.

"Klaas is a great penalty taker," Robben said. "He was fresh, had just come on and I had faith in him. I asked him if he wanted to take it, and he was very sure of himself.''

Huntelaar and Sneijder scored the goals at the hot and steamy Arena Castelao, but it was Netherlands coach Louis van Gaal who might just deserve the credit for making a crucial tactical change during the second of two official cooling breaks.

As he did earlier against Australia, the master tactician again switched his team around in the second half and changed from the more defensive 5-3-2 system to the traditional Dutch attacking 4-3-3 formation.

"Yes, we escaped,'' Van Gaal said. "But we showed that we could create more chances with 4-3-3, and the players handled this shift very well.''

Van Gaal said he made his critical switch during the second-half break, when he huddled with his players as they drank from bottles on the sideline.

"I moved to 'Plan B' at the cooling break after [Mexico goalkeeper Guillermo] Ochoa made an amazing save,'' said Van Gaal, who is soon to be the manager at Manchester United. "That is a good way to take advantage of those breaks.''

Ochoa had kept his team in the match with two great saves in the second half, but he was beaten by Sneijder's powerful drive and guessed wrong when diving in an attempt to stop Huntelaar's penalty.

The Mexicans had conceded only one goal in three group matches and looked like they would keep another clean sheet until the late collapse.

It was heartbreak again for Mexico, who have now reached the second stage of the World Cup six straight times without winning. The most recent time the team made the quarterfinals was when it hosted the tournament in 1986.

After the final whistle, the Mexican players collapsed, distraught on the turf while many of their fans were in tears.

Mexico coach Miguel Herrera blamed the referee for the loss and said Robben dived to earn the penalty.

"Today it was the man with the whistle who eliminated us from the World Cup,'' Herrera said.

"If a referee invents a penalty, you're out of the World Cup,'' Herrera added. "I hope they have a look at what happened and that this gentleman goes home just like we are.''

Herrera said Robben dove three times and blamed the referee for not reacting.

"If the referee is fair, then their second goal doesn't exist and Robben would have been expelled or suspended with a second yellow card," he said. "But if you do nothing the first time, then the player knows that the referee won't kick you out, he won't caution you, won't say anything."

It was the fourth straight win for the Netherlands at the World Cup after routing defending champion Spain 5-1 and beating Australia 3-2 and Chile 2-0 in Group B.

The Dutch will next face either Costa Rica or Greece in the quarterfinals on Saturday in Salvador.

"Unbelievable,'' Robben said. "Five minutes from full time, we were out.''

Mexico enjoyed a bright start to the game as Miguel Layun drove a cross wide on 14 minutes, before Hector Herrera dragged an effort off target, and then Dos Santos drew a save from the legs of goalkeeper Jasper Cillessen.

Van Persie spurned an opportunity for the Netherlands in the 27th minute, slicing wide, and just before halftime Robben had a strong shout for a penalty turned down following challenges by Marquez and Hector Moreno.

Mexico took the lead three minutes into the second half, when Dos Santos unleashed a left-footed shot from outside the area to flash the ball beyond the reach of Cillessen.

A combination of Ochoa and woodwork denied Stefan de Vrij after the defender diverted goalward from close range, only to see the ball pushed onto the post by the Mexico goalkeeper.

The Netherlands pushed for an equaliser, and their pressure told with two minutes of normal time remaining, as Sneijder thumped home from Huntelaar's headed assist.

Sneijder's goal in the 88th minute was the latest ever Dutch equalizer at a World Cup. It was Sneijder's sixth career World Cup goal and tied him for the second most in World Cup history.

And the comeback was complete three minutes into injury time, as Huntelaar tucked in from the penalty spot after Robben was tripped by Marquez.