Los Che had luck on their side as they got three penalties along with a Raphael Varane own goal to help them overturn Real Madrid's early lead from Karim Benzema's strike.
In a controversial moment in the match, the first of Valencia's three penalties had to be retaken, after Thibaut Courtois saved Carlos Soler's effort from the spot, despite the encroachment coming from Soler's teammate Yunus Musah.
Valencia then took the lead at the business end of the first half, courtesy a Raphael Varane own goal. The home side then got two more penalties in the second half to help them climb seven places in the table from 16th to 9th. Interestingly, Real Madrid's entire back-line made a mistake each leading to a Valencia goal - Lucas Vazquez, Marcelo and Sergio Ramos each gave away a penalty and Varane scored the own goal.
Real Madrid's poor run at the Mestalla continued, as they now slip to fourth in La Liga, four points behind leaders Real Sociedad.
Here's how we rate all the Valencia and Real Madrid players on the night:
Valencia player ratings against Real Madrid
Jaume Domenech - 7.5/10
The Valencia keeper had a dream night, making five saves including denying a 1 v 1 chance for Real Madrid talisman Karim Benzema early in the second half by rushing off his line to win the ball at the edge of the box.
Domenech couldn't do much about Real Madrid's opener as Benzema's shot was too powerful. But the keeper was solid for the rest of the match and was always in complete control of his box.
Daniel Wass - 7/10
The experienced and versatile Daniel Wass started in his more traditional Right-back position instead of the central midfield role he had been playing under Javi Gracia.
The Valencia full-back had a quiet night going forward, but kept Real Madrid's Vinicius Junior in check as the explosive Brazilian could not produce much from the left side and was unable to get behind Wass too often. The 31 year-old made three important interceptions and five clearances, but also lost possession a total of 11 times.
Gabriel Paulista - 7.5/10
The former Arsenal defender had one of his better nights at the back, making four interceptions and six clearances, not succumbing to the high pressure deployed by the Real Madrid forwards and midfielders.
Gabriel also won seven duels in the game and earned three fouls for his side, stopping Real Madrid's progression through the field on multiple occasions.
Hugo Guillamon - 6.5/10
Despite being partly culpable for Real Madrid's opening goal, Hugo Guillamon was strong at the back for much of the night. The young Valencia defender formed a solid partnership with the more experienced Gabriel Paulista and together they closed down spaces, not giving the Real Madrid attackers much room to navigate through in the final third.
Jose Luis Gaya - 7/10
To no one's surprise, Jose Gaya kept foraying into the box relentlessly to deliver numerous crosses. The left-back made Valencia's equalizer happen, as his fiery cross struck Lucas Vazquez's arm inside Real Madrid's penalty box in the 29th minute.
Yunus Musah - 6/10
The 17 year-old thought he had scored the biggest goal of his life in the 30th minute when he latched on the rebound from a missed Carlos Soler penalty, only for the goal to be ruled out due to Musah encroaching the penalty-kick by being half a boot inside the box. Fortunately, Soler slotted home the retake to begin Valencia's comeback.
Carlos Soler - 8.5/10
Rarely do you ever score a hat-trick, let alone a hat-trick of penalties. But Carlos Soler saw all of his lucky stars shine on the night as he scored thrice from the spot.
In fact, Soler took four spot-kicks as luckily for him, he was awarded a re-take after his first penalty being saved by Courtois, despite the encroachment being from Soler's own teammate Yunus Musah.
Uros Racic - 6.5/10
An active figure in the centre of the park, the Serbian midfielder delivered on his manager's trust in what was only his second start for Valencia in La Liga.
The 22 year-old was accurate with his passes in the middle of the park, but didn't create any clear chance for his forwards to latch onto and thus while performance was impressive, it wasn't imposing.
Denis Cheryshev - 6.5/10
The winger was awarded a start against his former club, Real Madrid, and made a couple of key passes that were ultimately inconsequential. Cheryshev couldn't create many opportunities for himself in front of the goal, but linked up well with his teammates, in the limited touches he took despite being on the field for 77 minutes..
Lee Kang-in - 7/10
19 year-old Lee Kang-in almost scored a goal for the ages, when he spun away from Ramos and let fly from outside the box early in the second half, only to be denied by a Courtois full-stretch save.
The Valencia teenage sensation looked to make something happen every time he was on the ball and made three successful dribbles before being taken off in the 81st minute due to an injury.
Maxi Gomez - 7/10
Sparkling in bits, Maxi Gomez had a few good touches on the right side of the field often releasing the explosive Yunus Musah to wreck havoc on Marcelo. Despite not taking any shots on goal himself, the Uruguayan won many important duels for his side allowing them to create more chances.
Toni Lato - 6.5/10
The left-back came on Denis Cheryshev in the 77th minute and won a couple of duels notably on the edge of Valencia's penalty box, denying Real Madrid any opportunity of staging a late comeback.
Kevin Gameiro - 6/10
Gameiro came on with the last ten minutes of normal left, as a replacement for the injured Lee Kang-in but couldn't make any noteworthy contribution in the handful of minutes he got. The striker lost possession a couple of times and failed to win the duels he committed into, but it hardly mattered as Valencia had an insurmountable lead by that point.
Jason - N/A
Jason came on in the 87th minute as like-for-like replacement for Yunus Musah and didn't have much to contribute in his nine minutes on the field. The winger had only a couple of touches and lost possession once.
Ruben Sobrino - N/A
Like Jason, Ruben Sobrino was subbed on in the 87th minute for Maxi Gomez. The Valencia forward won a duel and had a few touches, but given the circumstances of the game at that point, his contribution was too insignificant to earn a rating.
Real Madrid player ratings against Valencia
Thibaut Courtois - 6.5/10
Real Madrid's Thibaut Courtois would want to forget this night the moment he walked out of the pitch on Full-time. The Belgian's game was a tale of misfortune as everything went wrong for him despite not doing much wrong himself.
In fact, Courtois should have been the Real Madrid hero tonight. He saved Carlos Soler's first penalty, only for it to be retaken despite the encroachment being from a Valencia player.
He got his hand even on the retaken spot-kick, but it wasn't enough to stop it from going in. The 28 year-old went the right way on the subsequent two penalties as well, but just missed the ball on both occasions. He made another brilliant save from Lee Kang-in's shot in the second half.
But despite all these efforts, statistics will show the Real Madrid GK conceding four goals on the night and now going seven games in a row without a clean-sheet to his name.
Lucas Vazquez - 6/10
It seemed as if Lucas Vazquez was making the Real Madrid right-back role his own in the previous few games. But the versatile Spaniard put up a disappointing performance at the Mestalla, conceding the first penalty and losing possession on the field as many as 20 times while only two of his nine crosses found their target.
Raphael Varane - 5/10
A horrible night for Raphael Varane as the French defender's poor form continued from Real Madrid's midweek Champions League game against Inter. Varane was left with an egg on his face in the 43rd minute when he accidentally sliced the ball into his own net in an attempt to block Maxi Gomez's cross.
Sergio Ramos - 5.5/10
Real Madrid's captain fantastic was anything but fantastic on the night as he got mugged by teenager Lee Kang-in for a shot on goal and then conceded the third penalty of the game when he handled the ball during an attempted duel on Musah.
Ramos could have had a redeeming moment when he made an excellent last ditch block to keep the ball from going into the empty net, but Marcelo's earlier foul during the play meant Valencia got their second penalty of the night.
Marcelo - 5.5/10
Putting in less-than-impressive defensive shifts is nothing new for Marcelo. Throughout his career, the gifted left-back made up for his defensive weakness with his attacking prowess.
But it wasn't so on the night, as his assist for Benzema's opener couldn't mask his horrible show at the back. The Brazilian conceded the second penalty of the night bringing down Maxi Gomez in the box, despite Ramos' block having ensured Real Madrid weren't conceding a goal.
Federico Valverde - 7/10
Despite an overall horrible night for Real Madrid, their Uruguayan future star continued to impress. Federico Valverde made some explosive runs cutting through Valencia's midfield and maintained a 96% pass accuracy in the 76 minutes he was on the field.
Isco - 6/10
Isco got a rare opportunity as he made a comeback to Real Madrid's starting line-up. In the first half, it seemed like the technically gifted midfielder was making good on his chance making some important touches and creating a couple of chances. But as the game went on, Isco faded away and couldn't make any impact in the second half.
Luka Modric - 8/10
By far Real Madrid's best player on the night and perhaps the best player on the pitch, if we ignore Carlos Soler's hat-trick of penalties. At 35, the Croatian wizard is showing no signs of ageing and continues to boss the centre of the field.
The midfield maestro made 71 passes with an accuracy of 95%; and created two clear chances for scoring which Madrid's forwards failed to capitalize on.
Marco Asensio - 5.5/10
Marco Asensio once again showed sparks, but failed to produce fire. The winger displayed exquisite touches in crucial areas of the field, a reminder of the immense talent he possess.
But beyond that, Asensio does not seem to know what his job is on the pitch other than going for a shot at the moment. The 24 year-old often seems lost and isn't involved in Real Madrid's general play as much as he should be.
Karim Benzema - 7/10
Karim Benzema scored Real Madrid's opener with a powerful shot from just outside the box that hugged the top-right corner of the net. But aside from that, the forward didn't do much else and missed a few good goal-scoring opportunities after that.
Vinicius Junior - 5.5/10
One of those nights where nothing he tried came off. Like Asensio, Vinicius Junior too often seemed lost on the pitch especially in the second-half. The speedy Brazilian has all the talent in the world, but needs to start performing more consistently for Real Madrid. Vinicius fluffed a couple of good scoring opportunities and wasn't effective with his runs from the left flank.
Martin Odegaard - 7/10
Odegaard was subbed on for Vincius Junior in the 64th minute and straight away provided in the departments the Brazilian failed in. The 21 year-old made touches in important areas and created a good chance for Vazquez, only for the latter to blaze it over the bar.
Rodrygo Goes - 7/10
Rodrygo was subbed on along with Odegaard and played on the left side. The Brazilian completed a couple of dribbles and maneuvered a shot, albeit off-target. Rodrygo also created two chances after coming on and did all the right things which Vinicius and Asensio couldn't.
Toni Kroos - 7/10
Real Madrid star Kroos came on in the 76th minute for Valverde and quickly created a couple of good chances for his side. But with only 14 minutes of normal time left, the German midfielder couldn't do much to change the game.
Mariano Diaz - 6.5/10
Mariano made a rare Real Madrid appearance as he was subbed on along with Toni Kroos in the 76th minute. The Dominican striker had two shots off-target and won a couple of areal duels, but there was nothing he could really do to help his teams's cause.
Luka Jovic - 6.5/10
Luka Jovic came on for Isco for the last 13 minutes of the match and made a few passes and managed a shot. But the game was beyond Real Madrid's reach at this point and for what it's worth, Jovic impressed in the limited run-in he was given.