Malaga piled the pressure on Real Madrid boss Jose Mourinho by claiming a 3-2 win at the Rosaleda after Iker Casillas was controversially dropped.
All five goals came in a frantic second half, with highly rated playmaker Isco opening the scoring with a fine finish just after the break at 49 minutes.
A comical Sergio Sanchez own-goal levelled for Madrid, but substitute Roque Santa Cruz put the hosts back in front just after coming on.
Santa Cruz added his second and Malaga’s third with a superb finish after excellent play by the impressive Joaquin, who set up all three goals.
Karim Benzema pulled one back late on as Real rallied, but they struggled to break Malaga down as the team from the Costa claimed their first Liga victory over Real in 29 years.
The result leaves third-placed Real 16 points behind leaders Barcelona, while fourth-placed Malaga move to within two points of their manager Manuel Pellegrini’s former club.
It was some boost for Malaga, who were reeling from the news that they would be banned from next season’s European competitions over their failure to pay wages on time.
While replacement keeper Antonio Adan was not directly at fault for any of Malaga’s goals, his defence clearly missed the organisation and leadership abilities of skipper Casillas in what was a poor second-half performance.
They had done well in the opening 45 minutes, the better side as Willy Caballero miraculously kept out a swerving Cristiano Ronaldo free-kick, with the Portuguese missing a sitter before setting up Angel Di Maria, whose brilliant first touch was not matched by a weak finish.
In the dying seconds of the half Pepe headed a corner straight at Caballero, and it looked very much as if they would get a breakthrough, Malaga offering little other than the occasional good touch from Isco and Joaquin.
Whatever happened at half-time seemed to knock the wind out of Madrid though, as they scarcely turned up for the second half.
A poor defensive header from Pepe landed nicely for Joaquin, who dragged a pass to the edge of the box, where Isco arrived with a crisp low finish into the bottom left.
Adan had barely been tested but he had no chance due to the power and accuracy of the strike. He did not have to wait long to show his skills though as, soon after the opener, he saved well from Eliseu, while Joaquin put a low drive wide after a good run inside from the left.
Indeed, the hosts were suddenly all over Real as ex-Madrid forward Javier Saviola curled a snap-shot just wide after good play by Eliseu.
But the introduction of Kaka for Di Maria, who had drifted out of the game, changed the tide once again.
The Brazilian was heavily involved in starting the move that saw Ronaldo cross into the box, before continuing his run to head the ball down to Benzema.
The France striker, who was on the deck, tried to poke it back to Kaka, but his pass hit Sanchez and flew past Caballero.
It was an ugly goal but Real were inspired back to form, Mesut Ozil denied a solo goal by an excellent block from Sanchez, eager to make up for his early mishap.
However it was now Malaga’s turn to play a counter-attacking game and, with Madrid committing bodies forward, Joaquin’s inventive backheel from Jesus Gamez’s cross was saved by Adan only for Santa Cruz to arrive unmarked and tap home the loose ball.
Three minutes later it was 3-1, another fine run and pass from Joaquin finding Santa Cruz on the edge of the box, the on-loan Manchester City forward unleashing a first-time finish into the bottom left to effectively put the match to bed.
Benzema’s 82nd-minute strike was a joy to behold, Ozil’s lovely curling pass with the outside of his boot met with a rasping low finish by the Frenchman, and Real sensed a comeback as they pumped balls into the home side’s box.
But, marshalled by the excellent Sanchez and Martin Demichelis, Malaga held firm to close out a famous victory and leave Mourinho in a difficult situation following his decision to isolate his captain and the club's local hero.