Few would have predicted the outcome when Alexis Sanchez gave Barca the lead in the seventh minute, but Gerardo Martino's faltering side released their early grip on the game and went behind to goals from Dani Parejo and Pablo Piatti either side of half-time.
Lionel Messi responded quickly by equalising from the penalty spot, but Paco Alcacer scored the visitors' third goal on 59 minutes and this time Barcelona had no answer.
The Catalans remained top of the Primera Division on goal difference, but this defeat handed the initiative to the two Madrid clubs in the race for the title. Real and Atletico will both go ahead of Barca should they win their games on Sunday.
The Camp Nou paid tribute to the former Barcelona boss Luis Aragones, who died aged 75, before the game and the hosts made a strong start.
It was not long before they went ahead, Sanchez sending a low cross from Messi over the head of Valencia goalkeeper Diego Alves and into the net, although it looked as if the Chilean was attempting to play the ball back to a team-mate in the six-yard box.
Victor Valdes then stopped a stinging effort from Sofiane Feghouli, while Sergio Busquets and Dani Alves missed attempts to score a second for Barca, and Messi failed to convert three chances in a period of domination.
However, after the half-hour mark the visitors started to plot their way back into the game.
Ricardo Costa failed to take advantage of a failed attempt by Valdes to claim a cross and headed just wide of a post with the goal gaping and Juan Antonio Pizzi's side's confidence kept growing.
Valencia pulled level just before half-time, Parejo starting and then finishing off the move.
The midfielder fought off a challenge from Fabregas to hold on to the ball in midfield and drive towards goal, playing in Jeremy Mathieu on the right-hand side of the area then slotting in the return pass from 10 yards out.
Just three minutes into the second half, the visitors scored again. Feghouli got past Alba on the right to put in a cross and Piatti rose above Dani Alves to send a looping header towards the far corner. Valdes could only get a hand on it and watched it drop into the net.
Diego Alves did well to keep out an effort by Cesc Fabregas immediately after the goal, but was helpless to stop Messi's penalty on 54 minutes.
The spot-kick was awarded for a handball by Ricardo Costa, although the Valencia captain insisted the ball had hit his shoulder.
But it was not long before Valencia restored their lead. Once again Feghouli was allowed to get too close to the byline down the right-hand side and the Algerian pulled the ball back for Alcacer to drive past Valdes.
Dani Alves came close to scoring a late equaliser, firing just wide of the far post, while Alba, who had had a poor display at left-back, made things even harder for his team when he was shown his second yellow card of the game with 13 minutes remaining.
Messi almost scored a dramatic equaliser in injury time, gliding through the Valencia defence with the help of substitute Andres Iniesta, but shot just past the far post as even he proved powerless to prevent his team from losing for the second time in the league this season.