Spain had taken the lead in the 27th minute thanks to Xabi Alonso's penalty, but Robin van Persie answered with a superb diving header in the 44th minute to send the two sides into the halftime interval level at a goal apiece.
The second half belonged to the Dutch as Louis van Gaal's men scored four unanswered goals to cruise to a momentous victory.
Arjen Robben put Holland in front in the 53rd minute before Stefan de Vrij extended the lead 11 minutes later.
Van Persie and Robben then capitalized on a pair of howlers from Spain goalkeeper Iker Casillas in the 72nd and 80th minutes, respectively, to complete the rout.
"We played a fantastic game and were compact in defense and direct in attack," Van Gaal said after the match. "We put pressure on them at all times, and there's no need for me to tell you just how dangerous Van Persie, Robben and (Wesley) Sneijder can be on the ball. Maybe our fitness was a factor, especially in this heat and humidity. The team is also mentally strong and we showed that today."
The match started brightly for Spain, which controlled the tempo for much of the first half and eventually took the lead after 27 minutes.
Diego Costa earned a dubious penalty decision, going to ground under minimal contact from De Vrij's sliding challenge. But referee Nicola Rizzoli pointed to the spot and Alonso converted on the ensuing attempt to put the Netherlands in a dangerous position.
David Silva nearly doubled Spain's advantage two minutes before halftime when he collected a through ball from Andres Iniesta to go one-on-one with Jasper Cillessen, but the Dutch goalkeeper produced a fine save to keep the Spaniards at bay.
It proved to be a crucial save as the Netherlands leveled the score one minute later in spectacular fashion. Van Persie latched on to Daley Blind's long ball over the top and directed the delivery past the on-rushing Casillas with a brilliant diving header.
The Netherlands gained the lead inside the first eight minutes of the second half, and it was Blind who again provided some exquisite service.
The Dutch left-back picked out Robben's run between the two central defenders and the Bayern Munich man did the rest, bringing the delivery down with a deft touch before cutting it onto his favorite left foot and firing a shot that took a slight deflection on its way past Casillas.
Van Persie nearly added another in spectacular fashion when he found space on the right side of the penalty area and uncorked a shot with his weaker right foot, but the effort came back off the crossbar and Spain escaped the danger.
But it ultimately made no difference as Holland made it three in the 64th minute thanks to a set-piece opportunity from the flank.
Sneijder delivered a dangerous cross to the back post where De Vrij was waiting to nod the delivery off the woodwork and into the back of the net. There was a hint of interference on Casillas as Van Persie challenged the Spanish goalkeeper on the cross, but the goal was allowed to stand.
Spain's woes continued in the 72nd minute when Casillas failed to properly control a back pass, allowing Van Persie to swoop in and poke the ball into the empty net for Holland's fourth of the match.
The rout was completed eight minutes later and Casillas was once again at fault. The Real Madrid 'keeper was caught out of position and allowed Robben to glide into the center of the box with ease. Spain's defense retreated in cover of Casillas, but Robben managed to fire home a left-footed shot for his second of the game.
Van Persie's two-goal effort saw him take home Man of the Match honors. He will hope to help the Netherlands build upon this performance on Wednesday when it takes on Australia at the Estadio Beira-Rio.
"It's amazing. This is a dream come true for us and that's why we need to enjoy the moment," the Manchester United man said. "I think my equalizer came at just the right time and when Robben made it 2-1, it gave us a huge lift and hurt them badly. The key was to keep the pressure on till the very end, which we were able to do because we're in great shape."
Spain, also returning to action on Wednesday, will attempt to regroup before taking on a talented Chile side at the Maracana.