Media playback is not supported on this device
All the goals came in the third quarter, with Ricardo Sanchez giving Spain the lead, Alan Sothern levelling, and Alvaro Iglesias scoring the winner.
Ireland now take their place in the fifth to eighth place play-offs, their next game against France on Friday.
The team which finishes fifth will guarantee World Cup participation.
If Ireland fail to secure a top-five position, they must wait on the results of the continental championships to see if they can progress.
Ireland beat France on penalties in the final of World League 2 in Belfast in March.
Ireland accumulated 10 penalty corners but found Spanish goalkeeper Quico Cortes on top form, while Eugene Magee saw his final reverse shot skim past the post.
The Spanish appeared to come out with a bit more fire in the second half and Davy Harte had to make a smart save following a crash ball into the circle.
Spain won their first penalty corner in the 37th minute and brave first running by Johnny McKee saw him block the shot but land hard on his shoulder, resulting in a stretcher being called for the young Banbridge player.
Despite two great saves by Harte from the following penalty corner, Sanchez managed to flick the rebound into the net to give his side the lead.
Ireland equalised in the 44th minute from a powerful drag flick by Sothern.
Just a minute later, Spain took the lead when a mis-trapped penalty corner was sent crashing back into the circle for the free Iglesias to sweep in at the back post.
Fine efforts from Magee and Jeremy Duncan called Cortes into action once more and the goalkeeper excelled again to parry away.
Ireland head coach Craig Fulton said "We're happy with our performance, but they took their chances on the day and we didn't.
"It was a good game and it could have gone either way, we know the chances we created and on another day we'll definitely finish those".
Ireland: D Harte, J Jackson, C Cargo, A Sothern, E Magee, S O'Donoghue, J McKee, P Gleghorne, C Harte, S Loughrey, S Cole
Subs: J Carr, J Bell (Captain), M Bell, M Nelson, N Glassey, S Murray, J Duncan
Ireland retain hope of World Cup qualification despite losing 2-1 to Spain in the quarter-finals of World League 3 in Johannesburg on Wednesday.