Ronaldo blazed over from 15 yards after a quick free-kick caught Morocco out, Guedes's miscued attempt rolling invitingly to the five-time world player of the year.
Morocco went on to lose the game 1-0, becoming the first team to be eliminated from the worldwide tournament.
"Especially with the goal, we think that Ronaldo fouls [Khalid] Boutaib who was closest to him, and this cost us". He could not get the ball up and over a solid wall of defenders on either occasion.
Though Spain had besieged the Iranian goal in the first half, they were on the back foot for parts of the second, with Karim Ansarifard rifling into the side netting, and Saeid Ezatolahi having a goal ruled out for offside by the Video Assistant Referee (VAR) system. Bernardo Silva made a decision to take a short corner with the help of Joao Moutinho, who crossed a teasing ball to the six-yard box.
When they did manage to stop appealing and concentrate on playing, Morocco looked risky and were the dominant side in the second half.
It was his 85th worldwide goal, taking him beyond Hungarian Ferenc Puskas's European record, with only Iran's Ali Daei ahead of him on 109. Amrabat was furious at not being awarded a penalty after wrestling with Raphael Guerreiro.
Morocco's Nordin Amrabat has slammed the lack of use of VAR during his side's 1-0 defeat to Portugal.
Portugal have no such concerns and will seek to win the group in their final game against Iran, while Morocco face Spain, both on June 25.
Mehdi Benatia forced a smart low save from Rui Patricio at a corner for Morocco, before Hakim Ziyach skipped his way into the Portugal area, his goal-bound effort blocked by an outstretched leg.