Malaga looked to be cruising to their first victory in seven league and cup games when quickfire goals by Antonio Apono and Nabil Baha at the start of the second half put Antonio Tapia's side 2-0 up.
Malaga held that lead until 10 minutes go to, but they were stunned as second-bottom Osasuna struck twice in 60 seconds through Javad Nekounam and Miguel Flano to tie the scores up at 2-2.
Buoyed by that comeback, Osasuna must have fancied their chances of going on to claim all three points and make it two wins from two having recorded their maiden victory of the season against Almeria last weekend.
It was all to end in tears for Jose Antonio Camacho's side though as much-travelled striker Albert Luque, who had started the game on the bench, struck with six minutes to go to put Malaga back in front, before Pereira Eliseu sealed the win in injury time.
All six goals came in the second period, although both sides had chances to break the deadlock before the break.
Osasuna had the first decent effort in the 16th minute when Czech Republic winger Jaroslav Plasil did superbly to create a shooting chance only to see Inaki Goitia parry his effort.
Malaga went closer still two minutes later when Baha's shot struck the woodwork, and Osasuna had another let-off in the 32nd minute when Adrian Lopez and Eliseu both went close.
There was little sign of the entertainment to come as both sides returned to the changing rooms at the interval with the game still goalless, but Malaga needed just 10 minutes of the second half to change that statistic.
The goal came from a penalty when Osasuna midfielder Juanfran brought down another former Real Madrid product Javier Calleja inside the box, and Apono sent Ricardo Lopez the wrong way from the spot.
It was 2-0 just seven minutes later as Malaga took control of the game through Baha, who capped a fine move from the Andalusian side by diving in to head home Adrian's looping cross from almost on the line.
That was the way the score stayed until the 80th minute when Osasuna, who had doubled their goal tally for the season during the win over Almeria, gave themselves a lifeline through Nekounam.
He charged in at the far post to get on the end of Ludovic Delporte's deep cross before sending a thumping downward header past Goitia.
Goitia was then beaten moments later by another header, as Flano's slow-motion effort found the top corner following a corner by Massoud Shojaei as Osasuna defied the odds to get back on level terms.
Those two goals must have stunned Malaga, but the hosts managed to battle back and leave Osasuna empty-handed.
Luque's goal was the killer for Osasuna, as his shot from the edge of the area took a deflection before flying over Ricardo to put Malaga 3-2 up.
Osasuna threw players forward after that in a bid to snatch a point, but that left them exposed at the back and Eliseu took advantage when he broke in behind the visitors' defence, ignored a well-placed team-mate in the middle, and slotted a low shot past Ricardo to complete the scoring.