The central European minnows now top qualifying Group C after this famous victory, although Spain coach Vicente Del Bosque won't be too concerned with qualification a near certainty.
It was Spain's first Euro qualifying defeat since 2006.
And yet, having trailed for 65 minutes of this encounter after Juraj Kucka's free-kick, they had appeared to salvage a draw through Paco Alcacer's strike eight minutes from time.
Yet Al Ain's Stoch — now plying his trade in Abu Dhabi having fallen a long way since his heady Premier League days — had the last word.
Slovakia showed no early fear against their illustrious opponents and could have taken the lead after 11 minutes.
Captain Marek Hamsik played right-back Peter Pekarik into space and his cross was met on the volley by Robert Mak, but Iker Casillas made a stunning save one-handed to deny him.
The reprieve was short, though, as Real Madrid's Casillas quickly went from hero to villain.
Slovakia went in front on 17 minutes as Kucka's free-kick, which admittedly swerved, deceived Casillas, who seemed to move out of the way before getting only a faint touch as it flew down the middle of the goal.
That sparked a reaction from Spain as Cesc Fabregas's corner broke to Raul Albiol on edge of the six-yard box, but despite being given two bites at the cherry he ended up prodding the ball high and wide.
The champions were almost made to pay as Mak played a one-two with Hamsik and fired in a left-footed shot that might have been going wide, but Casillas took no chances and helped it around the post.
On the stroke of half-time Spain were within a whisker of equalizing but Slovak goalkeeper Matus Kozacik made a brilliant double save to beat out Diego Costa's header from another Fabregas corner and then react quickly to save Sergio Busquets's acrobatic volley from the follow-up.
Spain started the second period brightly and produced an identical move to Slovakia's at the start of the game, this time Kozacik saving one-handed from Fabregas.
Moments later Costa ran purposefully at goal and unleashed a low strike that forced Kozacik into another stop.
Spain seemed to be running out of steam when suddenly, with eight minutes left, they equalized.
There was more than a suspicion of offside about it but substitute Alcacer controlled Jorge Alba's ball over the top and fired confidently past Kozacik with the Slovakian defence desperately looking at the linesman.
Moments later Costa teed up Fabregas on the edge of the area but the Chelsea playmaker blazed over the bar.
But with just three minutes left Slovakia launched a classic, rapier counter-attack as Hamsik played substitute Michal Duris down the inside right channel to cross for fellow replacement Stoch to head home at the back post with Spain's rearguard stretched.