The Fluminense striker struck early in each half, the first a scrappy affair and the second a neat curled finish.
Neymar fired home another just before half-time while Spain did not help themselves, with Sergio Ramos missing a penalty before fellow centre-back Gerard Pique was sent off.
Brazil gave a raucous Maracana crowd a dream start as with just over a minute on the clock, Fred showed superb presence of mind as in trying to meet Hulk's cross he was buffeted by two defenders.
The ball rebounded off Neymar and Spain full-back Alvaro Arbeloa and, flat on his face, Fred managed to improvise and poke the ball past Iker Casillas.
Spain's goalkeeper was almost caught out by Paulinho's 13th-minute lob, backpedalling to palm the ball off the line before falling gratefully on the loose ball.
Arbeloa was then booked for a cynical pull on Neymar. The Barcelona new boy would have had a clear run on goal, sparking Brazilian claims for a red card despite the challenge taking place in the centre circle.
That sparked the second flashpoint of the early exchanges, with players from both teams having earlier squared off after Fernando Torres' foul on Marcelo.
Brazil custodian Julio Cesar tipped Andres Iniesta's long-range curler away from goal, Torres heading the resulting corner just wide of the near post.
Ramos was booked for hauling down Oscar on the edge of the box, with Hulk blazing wide from the free-kick, while Fred spurned a glorious chance when teed up by Neymar.
David Luiz saved Brazil with a remarkable sliding goal-line clearance after a fluent Spanish break ended with Pedro curling the ball past Cesar.
It was a timely intervention as Neymar doubled Brazil's lead a minute before half-time, hammering the ball inside Casillas' near post after exchanging passes with Oscar on the edge of the box.
Cesar Azpilicueta replaced the hapless Arbeloa at half-time but Brazil quickly extended their advantage.
Hulk and Neymar set up Fred to curl the ball inside the far post despite Casillas getting his fingers to the shot.
Hulk could have added his name to the scoresheet but Casillas charged out of his area to block the powerful frontman's lob.
Ramos' header was saved but the Real Madrid defender was to spurn a better chance to get his side back into the game.
Marcelo fouled substitute Jesus Navas in the box but Ramos drilled the penalty wide of the left-hand post.
David Villa replaced Torres before Navas had a shot deflected wide, Gerard Pique heading the resulting corner straight at Cesar.
Marcelo blazed into the side-netting for Brazil before apologising fulsomely to Fred, who was waiting in the six-yard box to be presented with a certain hat-trick.
Casillas again had to come off limits to foil Hulk while a sliding Villa was unable to meet Pedro's dangerous cross-shot at the other end.
Things got even worse for Spain when Pique was shown a straight red card for chopping down his new club-mate Neymar, who curled the free-kick just over.
Ramos shot wide again before resuming his defensive duties to block Fred's shot. Neymar was then crowded out when unable to pass the ball with Fred yards offside. The latter's hat-trick hopes disappeared in that moment as he was swiftly replaced by Jo.
Cesar made a superb reflex save from Pedro's powerful effort and Ramos, strangely Spain's primary attacking threat, headed Xavi's corner well wide.
Villa drew another good diving save from Cesar but Brazil were otherwise able to play out the closing stages with no alarms.
COMMENT RULES: Comments that are judged to be defamatory, abusive or in bad taste are not acceptable and contributors who consistently fall below certain criteria will be permanently blacklisted. The moderator will not enter into debate with individual contributors and the moderator’s decision is final. It is Belfast Telegraph policy to close comments on court cases, tribunals and active legal investigations. We may also close comments on articles which are being targeted for abuse. Problems with commenting? firstname.lastname@example.org