A win for Tahiti in the late game ensured an end to the tournament ambitions of UAE and USA.
Spain twice pegged back the west Asians who lead for lengthy periods of the contest.
Spain remained composed without dominating and eventually equalised through Antonio after a defensive error.
UAE retook the lead early in the third period and for a while seemed set for a famous victory.
But Spain, as they did in their tournament debut against USA, came from behind again.
Raul Merida, who scored twice, tied things up with a close range finish and from then on it was all La Furia Roja.