Spain squeezed 1-0 past dogged Iran in their World Cup Group B encounter on Wednesday thanks to a fortuitous goal from Diego Costa, but the Europeans suffered a string of second-half scares.
The Altetico Madrid forward notched his third goal in two games when Ramin Rezaeian's attempted clearance bounced off the Spaniard's leg and into the net in the 54th minute.
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.
The result left Spain joint top of their group with Portugal on four points, but Iran close behind on three going into the third and final set of games. After two defeats, Morocco are out.