Vicky Losada scored Spain's first ever World Cup goal after 13 minutes but just one minute later Raquel Rodriguez Cedeno did likewise for Costa Rica.
Losada, 24, picked up a cross from Sonia Bermudez into the penalty area, controlling well before firing past Dinnia Diaz in the Costa Rican goal.
Spanish celebrations were short-lived though when Rodriguez Cedeno picked up an Irene Paredes cross in the penalty area to slot in.
Spain, ranked 14th, missed a string of chances in the second half, but their 37th-ranked opponents stood firm, and next face South Korea on Saturday.
Spain's second group game will be against Marta's Brazil with their final group game against South Korea next Wednesday.