The contest was over within 31 minutes as Dani Olmo, Marco Asensio and Ferran Torres, from the penalty spot, rewarded one-touch passing and movement that Costa Rica could not live with.
Torres grabbed his second before Gavi - who became Spain's youngest-ever goalscorer in June - and substitutes Carlos Soler and Alvaro Morato completed the rout.
Spain's victory eclipsed their previous biggest World Cup win, a 6-1 defeat of Bulgaria in France 24 years ago.
La Roja have struggled on the World Cup stage since lifting the trophy in 2010 - exiting at the group stage in 2014 and being knocked out at the last 16 four years later.
But the nature of this victory will raise expectations that Spain can go deep in the competition and challenge for the main prize again.
Costa Rica were the last team to qualify for the World Cup by beating New Zealand in an intercontinental play-off in June.
But the Central Americans were out of their depth and did not manage a single goal attempt.
Group E had been thrown wide open earlier in the day by Japan's shock 2-1 victory over Germany.
But Spain were determined not to be the fall-guys of a similar upset and Olmo and Asensio had missed clear chances before the deadlock was broken after 11 minutes.
Pedri had fashioned the two earlier opportunities but this time Gavi, the other Barcelona teenager in a cultured Spanish midfield, provided the crucial assist.
Olmo played a clever one-two with Gavi and, capitalising on a slight deflection off Francisco Calvo, easily beat Keylor Navas with a wonderful dinked finish.
The lead was doubled after 21 minutes as Costa Rica were again cut apart with ease.
Sergio Busquets found Jordi Alba in space and his cross was swept home by Asensio from 14 yards, although Navas might have done better with a shot he got both hands to.
Costa Rica conceded again when Oscar Duarte caught Alba on the heel and Torres comfortably slotted away the penalty.
At that point Spain had enjoyed 87 per cent possession and their control was complete.
Asensio might have claimed a hat-trick either side of the interval but Torres added a fourth after 54 minutes, profiting from a mix-up in the Costa Rica defence to swivel and score from close range.
With the outcome decided and both sides making several substitutions, the contest lost intensity and felt more like an exhibition than a World Cup match.
But Spain scored a sixth after 75 minutes as Alejandro Balde's burst ended with Morata crossing for man-of-the-match Gavi to convert a brilliant volley with the outside of his foot.
There was even more agony for Costa Rica in stoppage time as Navas failed to deal with Nico Williams' cross and Soler slid home into an unguarded net.
Olmo then set up Morata two minutes later and his left-footed finish put the Spanish in seventh heaven ahead of meeting Germany on Sunday.