Although Spain controlled the contest, played before 39,368 at the home of baseball club 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 equalise, 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 team-mate Simon Cox was adjudged offside.
Mata sealed the victory in the 88th minute, collecting a pass from Santi Cazorla toward 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 head to Brazil for the FIFA Confederations Cup. They play Uruguay on Sunday in their first match of the competition in Recife.
"We achieved what we came to do," said Spain coach 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 Trapattoni 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 UEFA EURO 2012 drubbing by Spain.
"It was fantastic this time," Trapattoni said. "Our support, the Spanish support - the atmosphere was fantastic."