With the tie still level in the second of two five-minute halves of extra-time, Hungary finally made their move to win by a single goal and send the Basketball Arena into raptures.
Iceland, who had been tipped for gold, advanced through Group A of the preliminary stage with a 100 per cent record, which included beating France in a re-run of the Beijing 2008 final, while Hungary needed a final-day win over Serbia to book their place in the last eight.
But the start of the match did not go to form as the central Europeans raced into a 5-1 lead after five minutes, with Iceland struggling to adapt to the new surroundings of the Basketball Arena.
However, they did find their groove and they scored eight out of the next 11 goals to take the advantage at 9-8 for the first time after 20 minutes, but the back-and-forth nature of the first half continued as Hungary rattled in four unanswered strikes to earn a 16-12 lead at half-time.
A classic was unfolding as five successive goals from Iceland made it level and the score then advanced to 26-24 to Hungary, setting up a grandstand finish with five minutes left.
Iceland then produced a three-goal burst to edge into the lead for the first time since the 12th minute and it was well timed with 90 seconds remaining.
They had the chance to seal the win with a penalty in the final 15 seconds, but Snorri Steinn Gudjonsson missed and they were made to pay as Mate Lekai threw in with three seconds left on the clock to send the game into extra time with the scores at 27-27.
A tight first half of the additional period saw the score advance to 29-29 and that became 30-30 as a second set of two five-minute halves was required to separate the two teams.
Hungary finally earned some breathing space and scored two successive goals to lead 33-31 and it proved decisive as they were able to hold out to seal a famous victory.