After falling behind 1-0, the visitors got one goal apiece from Dennis Rodriguez, Johan Cordoba and Gerald Mena during a four-minute, first-period stretch to take a 3-1 lead.
Robles' first goal near the end of the first period, though, cut Costa Rica's lead to 3-2 and it was all El Salvador from there.
The Cuscatlecos went ahead for good when Agustin Ruiz, the top scorer in the 2012 edition of the competition, netted with three minutes left in the second period.
In the competition opener, Paraguay stunned Spain, 6-4, thanks to a three-goal performance by Juan Lopez.
On Friday, Spain will meet Costa Rica, while El Salvador takes on Paraguay.