Dirk Kuyt scored two goals in three minutes late in the game as the Dutch, pegged back to 3-3 in the 75th minute by Zoltan Gera's second goal, snatched a 5-3 win in Amsterdam.
Two goals in the last 20 minutes, one an own goal from Tadas Kijanskas and one from Juan Mata, gave Spain a 3-1 win on a muddy pitch in Lithuania after the world champions had Xavi's first-half goal wiped out by Marius Stankevicius.
It was a rare case of big guns having to work hard for the points in a tournament which has so far featured a dull procession of effortless wins by the top sides. The Dutch have six wins from six games in Group E while Spain have won all five in Group I and both are almost certain to top their groups.
The nine group winners will go straight to Poland and Ukraine in 2012 along with the best runners-up. The other eight second-placed teams play off for four more places. The World Cup finalists, 4-0 winners in Hungary on Friday, looked set for another easy victory when Robin van Persie, who later went off injured, gave them a 13th-minute lead. But Hungary capitalised on a sloppy Dutch start to the second half as they scored twice within five minutes through Gergely Rudolf and Gera.
Wesley Sneijder levelled just after the hour before a sequence of four goals in eight minutes saw Ruud van Nistelrooy put the Dutch ahead, Gera equalise and Kuyt score twice.
Sweden, chasing second spot in Group E, beat Moldova 2-1 as goals from Mikael Lustig and Sebastian Larsson made up for a Zlatan Ibrahimovic penalty miss just before halftime.
Alexandru Suvorov replied for the visitors as Sweden went level with Hungary on nine points, nine behind the Dutch. Czech Republic stayed six points behind Spain in second spot after Milan Baros and Michal Kadlec gave them a predictable 2-0 win over Liechtenstein. Turkey revived their hopes of finishing second behind unstoppable Germany in Group A with a 2-0 win over fading Austria.
Belgium, 4-1 winners over Azerbaijan, are second with 10 points while Turkey are third with nine, the Germans leading with a perfect record. Serbia and Slovenia missed a chance to dent Italy's Group C lead when they drew away, keeping both five points adrift.
Serbia drew 1-1 in Estonia after a blunder by goalkeeper Zeljko Brkic allowed Konstantin Vassiljev to equalise for the hosts in the 84th minute in snowy Tallinn, wiping out Marko Pantelic's opportunist first-half effort. Slovenia drew 0-0 in Northern Ireland.