SARANSK, Russia (AP) — Iran was knocked out of the soccer World Cup Monday night despite saving a Cristiano Ronaldo penalty that cost Portugal first place in its qualifying group.

Portugal ended up finishing second in Group B after a 1-1 draw with Iran. The 2016 European champions will next face Uruguay on Saturday in the round of 16.

Instead of Ronaldo, it was Ricardo Quaresma who scored for the Portuguese. The 34-year-old midfielder responded to his first start of the tournament by producing one of the more aesthetically pleasing goals of group play.

Quaresma became Portugal’s oldest scorer in World Cup play by hitting a curling shot from the edge of the penalty area that went beyond the reach of diving Iran goalkeeper Ali Beiranvand.

Quaresma’s goal came on a night when Ronaldo — who had scored all four Portugal goals in its first two games of Group B play — was denied on a penalty by Beiranvand.

Karim Ansarifard scored a late penalty for Iran, which need to win to advance but couldn’t break through a second time despite a furious charge in the waning minutes. Mehdi Taremi had a chance in stoppage time to score, and send Iran through at Portugal’s expense, but fired into the side-netting

Spain won the group after its 2-2 draw with Morocco. Both Spain and Portugal had a goal difference of plus-1, but Spain scored six goals in its three group matches while Portugal had five.

Spain will next face host Russia on Sunday in Moscow.

Quaresma had never scored in a World Cup game; he had nine international goals in 78 previous appearances. But his goal had all the flare of a Ronaldo strike. He sent the shot with the outside of his right foot right into the far corner near the end of the first half.

Not bad for someone who had played little more than 20 minutes as a substitute in Portugal’s first two games. Ronaldo certainly looked impressed, wrapping his right arm around Quaresma’s shoulders as he roared and raised his left fist into the air.

Ronaldo has now missed six of his last 14 penalty kicks, but he wasn’t the only big star to miss one in this tournament.

Argentina forward Lionel Messi also was denied in his team’s opening draw against Iceland.

Ronaldo’s penalty was awarded after the use of video review following an apparent takedown of the Portugal forward by Saeid Ezatolahi in the area. The Iranian team, already aggrieved by the replay system overturning a goal against Spain, reacted angrily. Players swarmed Paraguayan referee Enrique Caceres, who initially had waved play on after Ronaldo went down.

Beiranvand made it a moot point, but normally defensive-minded Iran still needed to score multiple goals to advance, and they were unable to do so against a squad that won the 2016 European Championship by virtue of its own strong defensive play.

Iran has now been to five World Cups — all since 1978 — but has yet to advance out of group play. Its players collapsed on the field at the final whistle while Portugal’s somewhat muted celebration had the look of relief.