The world and European champion overcame a turgid start and a spirited Irish outfit to seal a 2-0 win at Yankees Stadium ahead of this Sunday's Confederations Cup opener.
Goals from substitutes Roberto Soldado and Juan Mata ensured Vicente del Bosque's side the victory, but the team needed to overcome a determined Irish outfit to seal the win after a sluggish start to proceedings on the East Coast.
With the reigning world and European champion opening its Confederations Cup campaign in four days, the onus was on La Roja to perform admirably against the Irish ahead of the tournament, and the opening exchanges proved to be a distinctly slow affair.
Andres Iniesta fired a shot narrowly over the bar after a brilliant attacking phase in the early stages, but even though Del Bosque's side was typically dominating the possession count, it lacked the potency to trouble David Forde in the Ireland goal.
Nevertheless, the Boys in Green displayed plenty of fight to frustrate the more esteemed opponent - a far cry from last summer's capitulation at Euro 2012, and could've even taken the lead. Gerard Pique's indecision on the ball was punished by Sammon, who fired agonizingly wide when put one on one against Victor Valdes, in the half's best chance.
Spain, however, recovered from the poor opening as Ireland began to open up. Pique's header had earlier been cleared off the line by Paul McShane, before a neat pass from Pedro in towards David Villa was intercepted at the last moment by the Hull City defender.
Giovanni Trapattoni's men were beginning to ride their luck, and were fortunate to not fall behind. Xavi teed up Pedro, who expertly turned away from his marker before firing a thundering shot off the underside of the crossbar, before David Silva struck hopelessly over the bar from the rebound as Ireland breathed a sigh of relief.
The second half proved to be an equally dogged affair, as Ireland continued to frustrate its opponent. The flurry of substitutions just before the hour allowed the world champion to add a new dimension to its attack, and it almost paid dividends as Jesus Navas tested Forde, before Pique's shot was thwarted by the goalkeeper.
Ireland's resistance was to be broken, as the team finally folded. Darren O'Dea's poor clearance was picked up by Alvaro Arbeloa in an advanced position, before substitute Soldado struck cleanly past the impressive Forde to hand La Roja the lead. It could've been two seconds later had Jordi Alba not struck narrowly wide.
The visitors had a goal chalked off for offside, in controversial circumstances. From a corner, which was helped on into the path of Simon Cox, in an offside position, before the ball was poked home by Sean St Ledger, sending the sizable Irish contingent inside the stadium into raptures, soon dashed by the referee's interjection.
Spain rallied from that scare, and finished strongly. Santi Cazorla saw a dipping effort from distance tipped over by substitute Darren Randolph, with Sergio Ramos heading narrowly over the bar from the resulting corner. Mata wrapped up the game with a finely worked second goal, with a delightful chip over the goalkeeper on the back of a fine assist from Santi Cazorla.
Spain takes on Uruguay in their Confederations Cup Group B opener on Sunday at the Arena Pernambucano in Recife, as attention turns towards the tournament in Brazil.