Roberto Soldado in the 69th minute and Juan Mata in the 88th scored for Spain, while goalkeeper Iker Casillas contributed two stellar saves in the second half.
Although Spain controlled the contest, played before 39,368 at the home of Major League Baseball's New York Yankees, they had nothing to show for it until the 69th minute.
A poor clearance by Darren O'Dea was picked up by Alvaro Arbeloa and substitute Soldado fired it past David Forde.
A dogged Ireland had chances to equalize, most impressively in the 81st minute when James McClean got through on the left and fired off a shot that Casillas deflected.
Sean St. Ledger found the net, but teammate Simon Cox was adjudged offside.
Mata sealed the victory in the 88th, collecting a pass from Santi Cazorla towards the left post and sliding a shot past substitute goalkeeper Darren Randolph.
Spain, who beat Haiti 2-1 in a friendly in Miami on Saturday, now heads to Brazil for the Confederations Cup.
They play Uruguay Sunday in their first match of the competition in Recife.
"We achieved what we came to do," said Spanish manager Vicente Del Bosque. "I think it's been a good preparation, I think physically we've gotten better, and overall I think we're better than when we came."
Ireland manager Giovanni Trappattoni had admitted his team's chances of beating number one-ranked Spain were slim, although he predicted they would acquit themselves better than they did in a 4-0 Euro 2012 drubbing by Spain.
They did, and enjoyed the experience.
"It was fantastic this time," Trappattoni said. "Our support, the Spanish support — the atmosphere was fantastic."