Ireland must beat Egypt in their final group match today if they are to reach the semi-finals of the Meridian Cup.
Having taken Saturday's game to Spain and deservedly gone in front early in the second half, Brian Kerr's European champions simply wilted in the 32-degree, Cape Town heat. Spain's tactical guile and finishing did the rest as they won by a flattering scoreline.
Scarcely in the game until they equalised in the 66th minute, Spain cruelly punished tired defending to strike twice inside six minutes through Roberto Trashorras. Substitute Borja Burgos capitalised on an error by Irish goalkeeper Joe Murphy to add a third nine minutes from the end.
"We played really, really well, considering the conditions," said Kerr. "We had two great chances to score again after we took the lead and that would have been it.
"But they got back into it and then took the lead following a free kick that should have been ours. Only then did they truly show how good a side they are to punish us when we got very tired."
David McMahon continued his rich vein of goal-scoring to put Ireland in front two minutes into the second half. Liam Miller fed the ball to Brendan McGill up the right and McMahon headed home his cross at the near post. Remarkably, it was his sixth goal in the last seven games and makes him the highest scoring Irish youth international with 16 from 26 appearances.
Justifiably in the lead, Ireland should have sewn up the game in the next 10 minutes. Captain Shaun Byrne glanced a header wide from a Keith Foy cross while Gary Dempsey, hugely energetic before running out of steam in the second half, forced a back-pedalling, tip-over save from Spanish goalkeeper Iker with an audacious 50-yard shot.
Kerr had made just one enforced change due to the suspension of Jim Goodwin, sent-off in the opening win over South Africa on Thursday. In came John Thompson at right back with Dessie Byrne moving across to play in a central defensive role along side John O'Shea.
Byrne is now out of the Egypt decider after he picked up a second yellow card.
Republic Of Ireland (4-3-3): Murphy (Tranmere Rovers); Thompson (Nottm Forest), O'Shea (Manchester Utd), D Byrne (Stockport County), Foy (Nottm Forest); Dempsey (Everton), Miller (Celtic), S Byrne (West Ham); McGill (Sunderland), McMahon (Newcastle Utd), Reid (Nottm Forest). Subs: Butler (Sunderland) for Thompson (74 mins), Fitzpatrick (UCD) and Mattis (Huddersfield) for McGill and Reid (both 80 mins).
Spain (4-4-2): Iker (Real Madrid); Jose Antonio (Las Palmas), Jose (Sevilla), Dani (Barcelona), Aritz (Atletico Osasuna); Julio (Real Madrid), Manuel (Valencia), Mikel (Barcelona), Juanjo (Real Zaragoza); Trashorras (Barcelona), Aganzo (Real Madrid). Subs: Jacobo (Celta Vigo) for Juanjo (40 mins), Vincente (Levante) for Jacobo (half-time), Borja Burgos (Celta Vigo) for Aganzo (74 mins).
Referee: S Shmolik (Belarus).