Cristiano Ronaldo opened the scoring for the visitors but the home side produced a stunning comeback to take all three points
Leaders Madrid travelled to Mestalla to resume their season having won their last 22 competitive games, but were greeted by a fired-up, aggressive Valencia side not short on quality themselves.
The home side were superb from the off, but the newly-crowned Club World Cup champions still took an early lead courtesy of a controversial penalty from their talisman Cristiano Ronaldo - his 26th Liga goal of the campaign.
However, the hosts were undeterred and forced a thoroughly deserved equaliser shortly after half-time through Antonio Barragan's first Liga strike since March 2007.
And, roared on by a boisterous home crowd, Nuno Espirito Santo's men edged in front on 65 minutes when Nicolas Otamendi rose highest to power a towering header beyond Iker Casillas from Dani Parejo's excellent corner.
Carlo Ancelotti's side reacted in the manner of a side who many fancy to sweep the board in terms of major trophies this season, but Valencia stood firm and claimed an invaluable three points that move them above Sevilla and into the top four.
POST-MATCH FEATURE: Real Madrid pay price for money-making trip to Dubai
Valencia started on the front foot, with their up-tempo, high-pressing game denying Real space and time on the ball.
But despite the hosts' strong start, Real went in front after 14 minutes through - somewhat inevitably - Ronaldo.
Alvaro Negredo was adjudged to have handled Gareth Bale's flicked header from a Toni Kroos free-kick inside the area, and the Portuguese duly stepped up to send Diego Alves the wrong way from 12 yards.
If Madrid were slightly fortunate to be given that penalty, they had every right to feel aggrieved that referee Jesus Gil did not point to the spot again 11 minutes later.
Bale was again involved, and Lucas Orban clearly handled his cross towards Ronaldo.
However, the Ballon d'Or favourite should have scored anyway, as he somehow fired into the side-netting after latching onto the loose ball and rounding Alves.
Ronaldo was almost made to pay for his uncharacteristic profligacy on the stroke of half-time, when Andre Gomes' left-footed shot from 20 yards was deflected onto the post with Casillas stranded, before the Real skipper reacted quickest to deny Paco Alcacer on the rebound.
Gomes again went agonisingly close immediately after the restart, as he lashed a volley narrowly wide with Casillas beaten.
But Valencia finally got their just rewards courtesy of the most unlikely of sources in the 52nd minute, as Barragan's speculative shot took a wicked deflection off Pepe and gave Casillas no chance.
The home crowd were sent into raptures once again with 25 minutes remaining, when Otamendi powered a bullet header past Casillas from Parejo's outswinging corner.
Madrid were on the ropes and Valencia should have gone further ahead soon after, only for Barragan to side-foot wide following a free-flowing passing move.
Ancelotti's men quickly regained their composure and laid siege to their opponents' goal for the remainder of the game.
Sergio Ramos, Ronaldo and Isco all went close to finding a late leveller, but Valencia were not to be denied a famous victory as the Champions League winners were condemned to a first defeat since September.