Denmark headed into the showdown as the only unbeaten team in the tournament but looked overawed from start to finish as Spain produced an effervescent performance to repeat their 2005 success.
Wingers Valero Rivera and Victor Tomas led the Spanish effort by scoring 11 goals between them and their Yugoslav-born keeper Arpad Sterbik pulled off a string of stunning saves to thwart his bewildered opponents.
"It was incredible and we could never have imagined a final like this in our wildest dreams but the truth is we weren't nervous before the match," Tomas told the country's national TVE broadcaster.
"The whole team was really up for just enjoying it and it couldn't have turned out any better. Everyone came out and performed and we were convinced we could win the match."
Left back Alberto Entrerrios added: "We played a very good match with a sensational defence."
Having beaten Spain in the Euro 2012 semis en route to their second European gold medal, the Scandinavians had high hopes of winning their first world title after finishing runners-up in 1967 and more recently 2011, when they were beaten by Olympic champions France in extra time.
But Denmark they had no reply for Spain's fast-flowing game resulting in a barrage of fast breaks, while they struggled in attack with the tournament's top scorer Anders Eggert Jensen completely subdued.
Spain patiently built an 18-10 halftime lead and any hopes of a Danish comeback evaporated in the cauldron of Palau San Jordi after the home team scored eight unanswered goals in as many minutes after the break to delight their vociferous 13,000 fans.
With the lead swelling to 17 goals in the closing stages, Spain's bench turned to the crowd and danced joyfully well before the final whistle as Denmark coach Urlik Wilbek motionlessly watched his team's collapse.
Croatia won the bronze medal on Saturday, their third in a row after they also finished on the podium in Euro 2012 and the London Olympics.