Goals from Saul Niguez and Sandro Ramirez gave their side a two-goal advantage and although Bruma's stunning volley halved the deficit, Inaki Williams scored a late third to all but confirm Spain's place in the semi-finals.
During the opening stages, Portugal controlled the pace of the game and had a number of opportunities to take an early lead, but after Bruno Fernandes had volleyed over from distance, Daniel Podence struck the inside of the post from 20 yards.
However, slowly but surely, Spain began to assert themselves and midway through the first half, they went ahead through Saul who saw his deflected effort find the bottom corner after he had brilliantly moved past four Portugal players.
Once the game was past the half-hour mark, Spain came back into the match with Gerard Deulofeu curling over from the corner of the area and Hector Bellerin being denied by a smart save from Bruno Varela.
Five minutes before the break, Ramirez - a summer target for Everton - found himself in time and space on the edge of the penalty area but his half-volley went wide of the post.
During the opening moments of the second half, Fernandes had two openings to get Portugal back on level terms but after driving a shot straight at Arrizabalaga, he curled another effort wide of the far post after cutting into the penalty area.
Portugal went past the hour mark having the better of proceedings but on 64 minutes, Spain doubled their lead when Ramirez converted from close range after getting on the end of Deulofeu's low cross.
The goal effectively left Portugal needing three goals to stay in the tournament but they managed to halve the deficit with 13 minutes left through an outrageous effort from Bruma, who found the corner with a volley from 25 yards out after getting on the end of Hector Bellerin's headed clearance.
Portugal needed to remain on the attack, but that also led to more space in their own penalty area, and Denis Suarez exploited that with a shot which just missed the far corner.
With the last kick of the game, Spain made sure of the points with a third through Williams, who ran half of the length of the pitch before finding the bottom corner from just inside the penalty area.
It leaves Spain needing just a point from their game with Serbia to guarantee a place in the last four but given their superior goal difference, only a heavy defeat will prevent them from moving closer to the trophy they last won in 2013.