Substitute Reza Ghoochannejhad scored an injury-time goal to lift Iran to a 1-0 win over UAE and the top spot in Group C at the Asian Cup on Monday.
Despite a free-flowing game, and a virtuoso performance by UAE playmaker Omar Abdulrahman, neither side could find a breakthrough until Ghoochannejhad's late strike helped Asia's top-ranked team avoid a likely quarterfinal showdown with Japan.
UAE appealed for offside when Ghoochannejhad pounced on a ball that had ricocheted off teammate Andranik Teymourian and directed his header into the top corner from close range. However, television replays indicated the striker had just stayed onside.
"The spirit is great in our team, (the) chemistry is amazing," said Ghoochannejhad. "Right now everybody is happy but we have to focus on our upcoming games."
Iran will now face the runners-up of Group D, likely to be Iraq or Jordan, in the quarterfinal at Canberra on Friday, while the UAE will likely face Japan in Sydney.
UAE had already secured its quarterfinal place with wins over Qatar and Bahrain in its first two games, and was unlucky to not get the draw it needed to top the group from Iran on goal difference.
"Sometimes you play good and you lose, but sometimes also you don't play good and you win," said UAE coach Madhi Ali. "We have to forget this game. We lost, but we did not lose the qualification, and now we have to concentrate on our game against Japan.
"We don't have any problem playing with Japan or any other team."
UAE's chief playmaker Abdulrahman created several chances in the best individual performance of the tournament so far as he frequently skipped past bemused Iranian defenders and picked out teammates with his wide range of passing.
Both teams played with little caution as they looked for the crucial opening goal and UAE's Khamis Esmaeel almost delivered it with a powerful long-range strike that went just past the post with Iran goalkeeper Alireza Haghighi beaten in the fifth minute.
Iran quickly recovered from UAE's bright start and had a chance to take the lead in the 17th minute but defender Morteza Pouraliganji missed with his headed shot when it seemed easier to score.
Abdulrahman then produced a teasing run from the edge of the box and beat four Iranian defenders before the diminutive midfielder was tackled by Vahid Amiri as he honed in on goal.
Just before half-time Iran's Azmoun Sardar raced to the backpost to meet a corner kick, which had been flicked on by Teymourian, and his goal-bound header hit the chest of a UAE defender and deflected wide.
The game stretched further in the second half with UAE's Ali Mabkhout missing a couple of good chances to add to his three tournament goals so far, including one in 14 seconds against Bahrain.
Iran grew increasingly desperate and coach Carlos Quieroz introduced stars Ashkan Dejagah and Ghoochannejhad late in the second half in search of a breakthrough.
With full time closing in former Charlton Athletic striker Ghoochannejhad popped up to clinch the win for Iran, despite the pleas of the UAE defense for offside.
At Sydney, Sayed Jafaar produced a stunning long-range strike in the 82nd minute to lift Bahrain to a 2-1 victory over Qatar for its first win of the tournament.
Earlier, Sayed Shubber had produced a smart turn and finish past a host of Qatari defenders to score in the 35th minute, before Hasan Al Haydos equalized for Qatar from a free kick in the second half.
It ended a disappointing tournament for 2014 Gulf Cup champions Qatar, which lost all three games to finish bottom of the group.
"When you miss chances, it is due to many things," said Qatar coach Djamal Belmadi. "It is partly luck, concentration and quality of the player.
"From my experiences as a player, when you create a lot of chances and do not score, you usually lose the game."
On Tuesday, Japan will top Group D if it avoids defeat against Jordan at Melbourne, while Iraq plays Palestine at Canberra also looking to confirm its quarterfinal spot.