Goals from Jorge Carlos Martins, visiting defender Sergio Ramos, who put into his own net, Helder Postiga and Hugo Almeida sealed a deserved win for the Portuguese, who were knocked out at the last-16 stage in South Africa as Spain went onto win their maiden FIFA World Cup crown.
One of the reasons for tonight's match was to promote the two Iberian countries' joint bid to host the 2018 FIFA World Cup, but off-field alliances were firmly put to one side in a hard-fought and entertaining encounter at the Estadio da Luz.
Spain coach Vicente del Bosque started with ten of the side that began the FIFA World Cup final, with David Silva coming in for the ill Pedro Rodriguez as the only change. However, it was Portugal who enjoyed the better of the first half with wide men Cristiano Ronaldo and Nani featuring heavily.
Nani produced the first effort of the match in the second minute, his low 20-yard drive being turned behind by Iker Casillas, before Real Madrid star Ronaldo and Spain midfielder Sergio Busquets both picked up bookings in quick succession for crunching challenges on the other.
A fired-up Ronaldo cut inside Gerard Pique before scooping a shot over Real team-mate Casillas. The effort was going in but Nani headed the ball over the line from point-blank range and the goal was ruled out for offside.
Ronaldo was far from pleased, throwing his captain's armband to the floor, but the world's most expensive player would have been happier eight minutes later after playing a key part in helping Portugal take the lead. Martins had already gone agonisingly close to putting his side ahead just previously when his well-struck volley was headed off the line by Pique, but Spain did not survive a second time.
Ronaldo showed great skill and strength to muscle his way past Busquets before firing in a thunderous shot from a tight angle that Casillas could only parry, and Martins slammed the loose ball home from near the penalty spot.
Both teams made a number of changes at the break, with Ronaldo among the players to make way and Spain striker Fernando Torres - who had been a doubt after suffering an ankle strain playing for Liverpool at the weekend - among those introduced.
The first effort of the second half came from Spain, with Xabi Alonso attempting an audacious long-range lob that almost caught out Rui Patricio, but 60 seconds after that Portugal doubled their advantage. A good pass from Nani put Joao Moutinho in on the right and his low cross found its way into the back of the net via team-mate Postiga and Spain right-back Ramos. Postiga's back-heel may have been going in but Ramos put the ball in whilst attempting to clear.
Portugal should really have made it 3-0 in the 52nd minute but Nani's attempted chip over Casillas was comfortably saved. Reigning world and European champions Spain attempted to rally, with Cesc Fabregas going close with a volley, but Portugal wrapped up a comprehensive win with two more goals in the final 23 minutes.
Postiga made it 3-0 following good work by Danny and Moutinho before substitute Almeida completed the scoring after being put clean through by Pepe in injury time, a goal that sealed a third successive win for new Portugal coach Paulo Bento since he replaced Carlos Queiroz in September.