Substitute Roque Santa Cruz struck twice in three second-half minutes to help fourth-placed Malaga heap the pressure on Real Madrid coach Jose Mourinho, who created a surprise by omitting captain Iker Casillas from his starting line-up.
Madrid dominated the first half but were unable to turn their possession into goals and were made to pay as Isco put Malaga ahead in the 48th minute.
Karim Benzema drew Madrid level midway through the second half but Santa Cruz, who had been on the pitch less than 10 minutes, stunned the visitors by putting Malaga 3-1 ahead with a double strike in the 73rd and 76th minutes.
Benzema pulled another goal back with eight minutes remaining but Madrid could not find an equaliser as they slumped to a fourth league defeat of the season - twice as many as they suffered in winning the title last season.
Real are now 16 points adrift of leaders Barcelona but when Mourinho was asked if he feared the sack, he added: "Fear for my job? I have never feared for my job.
"Football has no memory. The only thing that matter is the present, not the titles you have won."
Barcelona made their rivals pay and gave stand-in coach Jordi Roura a winning start as goals from Xavi, Lionel Messi and Cristian Tello helped them win 3-1 at Real Valladolid.
Roura is deputising for Tito Vilanova, who was discharged from hospital on Saturday after undergoing an operation on his parotid gland on Thursday, and saw his side take a 1-0 interval lead when Xavi tapped in Jordi Alba's cross.
The Spain midfielder then set up Messi for his 91st and last goal of an extraordinary 2012 and, after Javi Guerra pulled one back, Tello rounded off the win in injury time.
Mallorca got their first win in 15 games in all competitions as they came from behind to beat Champions League-chasing Real Betis 2-1 at the Benito Villamarin.
Benat's free-kick had given the hosts an early lead, but Victor brought the Islanders level with a fine header on the half-hour mark.
And the comeback was completed just two minutes into the second half when Mario's challenge on Victor was deemed to have taken place inside the area and Javi Marquez comfortably slotted home the resultant penalty.
Granada climbed out of the relegation zone with a deserved 2-1 victory over fellow strugglers Osasuna at the Reyno de Navarra.
Nino had fired the hosts into an early lead with a looping header from Raoul Loe's flick-on, but Granada dominated thereafter and should have been level well before Diego Mainz did find the back of the net from Dani Benitez's free-kick four minutes before half-time.
And Benitez himself notched the winner two minutes into the second period with a wonderful left-footed strike from outside the area that left Andres Fernandez helpless.
Real Zaragoza edged above weekend opponents Atheltic Bilbao with a 2-0 victory at San Mames.
The visitors went in front shortly after the hour mark, with Jon Aurtenetxe's clumsy challenge on Victor Rodriguez resulting in a penalty.
Apono made no mistake from the spot as he drilled low into the bottom corner.
Zaragoza doubled their lead, and wrapped up the points, three minutes before half-time when former Tottenham forward Helder Postiga grabbed his eighth goal of the season.