The goals came from David Silva and Paco Alcacer in the first half, with Costa snatching the third on 69 minutes, while substitute Juan Bernat made it 4-0 with a debut goal on 87 minutes.
Spain, who lost to Slovakia on Thursday, are now second on goal difference in Group C on six points from three games, with Ukraine, also on six points, in third.
Slovakia's 3-1 away win at Belarus left them top with nine points from three.
Silva got the opener when he latched on to an uncharacteristic long ball out of defence after 27 minutes. The 21-year-old Valencia striker Alcacer doubled the tally with his third goal in three games for Spain just before half-time.
Costa, in his seventh match for Spain had missed a hatful on the night before he swivelled to fire home from close range to the visible relief of the whole team.
"Diego wanted to pay us back with goals for the support we've given him. He feels good in the group, but I told him at half-time he was thinking too much about it (getting a first goal) so I just told him to keep calm," coach Del Bosque said after the game.
The Brazilian-born Costa has been on fire in England with nine Premier League goals for Chelsea this season, but that was his first goal in seven for Spain.
Bernat, a Bayern Munich left-back, will also have given Spain reason to smile as a younger generation emerges to refresh their ageing squad.
Eyebrows were raised before tha game when Spain handler Vicente Del Bosque dropped the under-performing 'keeper Iker Casillas, the 33-year-old with whom Spain won Euro 2008 and 2012 plus the 2010 World Cup, in favour of Manchester United stopper David de Gea.
For his part de Gea had little to do, but was assured on the few occasions he was called upon.