Zoltan Gera gave Hungary the lead with a stunning strike from outside the area, before Nani slipped the ball past Gabor Kiraly to draw the sides equal.
Hungary retook the lead shortly after the break through a deflected Balazs Dzsudzsak free-kick, before a slick flick from Ronaldo brought Portugal level again just minutes later.
But Dzsudzsak got his second minutes later, only for Ronaldo to equalise once more with a perfectly-placed header.
Portugal had the first chance when the ball expertly floated over to Nani, who failed to get the ball under his control.
But it was Hungary who took advantage of Portugal’s fragility at the back to break the deadlock, Gera unleashing a rocket half-volley that flew into Rui Patricio’s bottom left corner.
They could have had a second just five minutes later, when Adam Szalai and Akos Elek combined after a Pepe slip only for Rui Patricio to get down low to deny Hungary a two-goal advantage.
A succession of Ronaldo free-kicks failed to pull Portugal back into the game, before they had a goal disallowed for offside after Pepe cut the ball back to Nani.
But Portugal got their reward just before half-time, when Nani found the bottom left-corner after a sublime through ball from Ronaldo.
It didn’t take long for Hungary to regain the lead after the break, when Dzsudzsak’s free-kick took a heavy deflection off Andre Gomes’ shoulder leaving Rui Patricio helpless.
Their lead didn’t long last however as Ronaldo cleverly flicked the ball through his legs and into the bottom corner.
But another stroke of luck gave Hungary the advantage once more, when another Dzsudzsak shot deflected past an outstretched Rui Patricio.
Ronaldo scored his second of the game just after the hour mark, nodding home Ricardo Quaresma’s cross to take it to honours even once more.
Dzsudzsak 47, 55
Ronaldo 50, 62
Referee: Martin Atkinson 7/10
Match rating: 5/5
Star man: Cristiano Ronaldo (Portugal)
Hungary: (4-2-3-1): Kiraly 5, Lang 6, Juhasz 6, Guzmics 7, Korhut 6, Gera 7 (Bese 45), Pinter 6, Lovrencsics 6 (Stieber 83 5), Elek 6, Dzsudzsak 8, Szalai 7(Nemeth 71 6)
Portugal: (4-4-2): Rui Patricio 5, Vieirinha, Pepe 7, Carvalho 6, Eliseu 6, Joao Moutinho 6, Andre Gomes 7, Ronaldo 8, Nani 7 (Danilo 81 5)