Luis Suarez opened the scoring in the 10th minute from a free kick. A Denis Cheryshev own goal doubled the advantage 13 minutes later.
Russia’s woes continued towards the end of the first half when defender Igor Smolnikov was dismissed for two yellow cards within nine minutes.
After that it was a question of damage limitation and the hosts did well to keep Uruguay at bay until second half stoppage time when Edinson Cavani scored his first goal of the tournament.
Uruguay, as winners of Group A, will take on the Group B runners-up Portugal. Ricardo Queresma stole the limelight from Cristiano Ronaldo in Saransk with a spectacular strike just before half time. Ronaldo then missed a second half penalty and his side nearly paid the price.
Karim Ansarifard levelled from the penalty spot in the third minute of second half stoppage time after the referee, Enrique Caceres, consulted the video assistant referee (VAR) and Iran nearly won it at the death but Mehdi Taremi hit the side netting with the goal begging.
Iran coach, Carlos Queiroz, hit out at the VAR system before the game complaining that the rules over when it is used are unclear. And he launched another attack on the technology after the match claiming that Ronaldo should have been sent off for using an elbow in a scuffle with Morteza Pouraliganji towards the end of the match.
"I don't want to talk too much as it's about my country and a player and I know it'll be a war against me," said Queiroz, who coached his native Portugal at the 2010 finals in South Africa."
"But the reality is you stopped the game for VAR, there is an elbow," he added. "An elbow is a red card in the rules. In the rules it doesn't say it cannot be used if it is Lionel Messi or Ronaldo.”
While Iran return home with a gnawing sense of what could have been, Spain will continue with a vivid hope that their best days are to come.
Fernando Hierro’s players had to come from behind twice to force a 2-2 draw against an already eliminated Morocco side that was playing for pride in Kaliningrad.
The Spaniards, who finished like Portugal, with five points and an identical goal difference, advance as Group B winners to a last 16 showdown with Russia in Moscow because they scored more goals than Portugal.
"The first conclusion I draw is that despite all these challenges we ended on top,” said Hierro, who took over the team when Julen Lopetegui was sacked just before the tournament. “I'm looking at the silver lining,” he added. “Obviously we can improve. To concede five goals in three matches is not the way forward. The players are professional. They understand the situation."