An unfortunate Martin Dubravka own goal set the 2010 world champions on their way before further goals from Aymeric Laporte, Pablo Sarabia, Ferran Torres and another own goal from Juraj Kucka completed the lopsided scoreline.
Spain, who will play Croatia in the round of 16, finished Group E in second place with five points from three matches. While Slovakia, who were eliminated with the loss, end their group campaign in third place with three points.
Spain's day began with a thud when Alvaro Morata saw his penalty well-saved by Dubravka in the 12th minute. But the Newcastle goalkeeper proved more generous at the half-hour mark when he inexplicably punched the ball into his own net after a Sarabia shot hit the crossbar and fell toward him in the six-yard box.
Spain, who had dominated up to that point, piled on from there, with Kucka's own goal from close range capping an impressive performance for Luis Enrique's men.