Simone Zaza, who endured an unhappy loan spell at West Ham United earlier this season, gave Valencia the lead in the fifth minute with a brilliant shot on the turn and Fabian Orellana added the second in the ninth.
Cristiano Ronaldo headed Real back into contention just before halftime, but the visitors were unable to build on their momentum after the break.
Real remained top on 52 points, one ahead of Barcelona and three clear of Sevilla in third, and still have one game in hand on both of their title rivals.
"The truth is we lost the game in 10 minutes. We started well with the ball, we had chances but we made two errors and they scored two goals. We had 80 minutes to rescue the game and tried but we lacked many things today," Real coach Zinedine Zidane told reporters.
"We had the chance to pick up points and we didn't do it. I hope this has no psychological effect on us. We need to be more focused in future games because if you don't concentrate you get punished. In those 10 minutes we weren't clever or ready."
Real's match at Valencia was rearranged after the original fixture was postponed in December due to Zidane's side taking part in the FIFA Club World Cup.
Valencia have endured a nightmare season filled with dismal results and upheaval off the pitch, but they got off to a flying start when a long pass from goalkeeper Diego Alves found its way to Zaza, who swivelled and fired the ball into the far top corner.
Real Madrid's Gareth Bale (L) and Valencia's Joao Cancelo in action
REUTERS Zaza, who joined Valencia in January on loan from Juventus after flopping at West Ham, scored his first goal for his new club in Sunday's 2-0 win over Athletic Bilbao. He was a constant thorn in Real's side, linking up superbly with wingers Nani, Orellana and Munir El Haddadi.
Real responded with a wayward shot from Toni Kroos but left themselves exposed on the break and were soon another goal down as Zaza spread the play to Nani and Orellana darted on to the Portuguese's pass to knock the ball through keeper Keylor Navas's legs.
Valencia might have got a third had it not been for a decisive block from Marcelo on Munir's shot, and the Brazilian played a crucial role in giving Real a foothold in the game, sending an arcing cross into the box which Ronaldo leapt to head past Alves.
Gareth Bale was brought on to help Real's push for more goals in the second half but they barely mustered a decent attempt while Munir had a strong penalty appeal waved away at the other end.
RESULT:Valencia 2 Simone Zaza 4, Fabian Orellana 9
Real Madrid 1 Cristiano Ronaldo 44
Standings P W D L F A
Pts1
Real Madrid 22 16 4 2 57 20
522
Barcelona 23 15 6 2 63 19
513
Sevilla 23 15 4 4 46 28
494
Atletico Madrid 23 13 6 4 43 19
455
Real Sociedad 23 13 2 8 36 32
416
Villarreal 23 10 9 4 30 15
397
Eibar 23 10 5 8 36 31
358
Athletic Club 23 10 5 8 28 28
359
Celta Vigo 22 10 3 9 36 36
3310
Espanyol 23 8 8 7 30 31
32