Lionel Messi had given the hosts the lead when he combined with Antoine Griezmann before slotting into the far corner.
Barcelona missed several opportunities to add to their lead before Darwin Machis drove in the equaliser in the second half.
Substitute Jorge Molina then headed in the winner for the visitors late on.
Victory would have put Barcelona one point clear at the top of the table with five games to go but instead they stay third, two points behind leaders Atletico Madrid and level with Real Madrid.
Barcelona and Atletico Madrid meet in what looks set to be a crunch battle in the title race on Saturday, 8 May.